ariovistus / pyd

Interoperability between Python and D
MIT License
157 stars 32 forks source link

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

Open mw66 opened 3 years ago

mw66 commented 3 years ago

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 commented 3 years ago

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

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

ariovistus commented 3 years ago

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

mw66 commented 3 years ago

Ubuntu / python3.6