Embedded python not picking up PYTHONPATH

2.8k Views Asked by At

I have a really weird problem with embedding python. If I don't specify PYTHONPATH, Py_Initialize fails with ImportError: No module named site.

If I set PYTHONPATH in cmd and then run my program, it works!

If I set PYTHONPATH programmatically (_putenv_s / SetEnvironmentVariable) it fails with ImportError again.

I've checked that the value is set with system("echo %PYTHONPATH%");, I've made sure multiple times that it is the correct path. I have no idea why it's failing... any ideas appreciated.

Setup: win10 x64, stackless python 2.7 x86 embedded in a C program.

2

There are 2 best solutions below

1
toster-cx On BEST ANSWER

Turns out I had to set PYTHONPATH before, then load the dll with a delay. The python library I have seems to be non-standard / modified.

0
Ben Cheng On

https://bugs.python.org/issue28245

I found that python37._pth could be used to configure the sys.path info.

python37.zip
.
Lib
Lib\site-packages

# Uncomment to run site.main() automatically
#import site