pythoncwinapipython-stackless

Embedded python not picking up PYTHONPATH


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.


Solution

  • 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.