pyd icon indicating copy to clipboard operation
pyd copied to clipboard

Doc: add workaround AttributeError: module 'sys' has no attribute 'argv'

Open mw66 opened this issue 5 years ago • 3 comments

I tried some code like this:

    py_init();
    po = py_eval("MyClass()", "mymodule");  // mymodule.py exists and is on PYTHONPATH

When I run it, it errors out:

pyd.exception.PythonException@/home//.dub/packages/pyd-0.13.1/pyd/infrastructure/pyd/pydobject.d(59):
AttributeError: module 'sys' has no attribute 'argv'
----------------
??:? [0x555555d88025]
??:? [0x555555db0326]
??:? [0x555555d93e9d]
exception.d:46 [0x555555c299d6]
pydobject.d:59 [0x555555c2e10c]
embedded.d:54 [0x555555c2956e]
/home//.dub/packages/pyd-0.13.1/pyd/infrastructure/pyd/embedded.d:235 [0x55555575b92e]
my.d:35 [0x555555757c59]
...

I googled a bit, and find this maybe related:

https://github.com/googleapis/oauth2client/issues/642

and the suggestion is:

Workaround is to start embedded script with:

import sys

if not hasattr(sys, 'argv'):
    sys.argv  = ['']

tried to add in mymodule.py at the top, and it worked.

Thanks.

mw66 avatar Oct 29 '20 00:10 mw66

I tried to add in mymodule.py, it seems working.

But I think this info should be added to the pyd doc README.md

mw66 avatar Oct 29 '20 00:10 mw66

This is curious. I am not seeing this behavior on fedora/python38. What are you running on?

ariovistus avatar Dec 20 '20 03:12 ariovistus

Ubuntu / python3.6

mw66 avatar Dec 20 '20 22:12 mw66