1

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.

1
  • 1
    I'm going to place my bet on failure to account for file system redirection. Without seeing any code, information on the execution environment, nor even the input to _putenv_s, this remains to be a guessing game. You'll need to improve your question to receive better answers. Commented Feb 9, 2017 at 17:20

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

I have tried but not work. my version is Python 3.7.0rc1 (v3.7.0rc1:dfad352267, Jun 12 2018, 06:15:26) [MSC v.1914 32 bit (Intel)] on win32. Beside, I print sys.path cannot find the PYTHONPATH content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.