New submission from Mario <mariofut...@gmail.com>:
According to the doc Py_GetProgramFullPath() should return the full path of the program name as set by Py_SetProgramName(). https://docs.python.org/3/c-api/init.html#c.Py_GetProgramFullPath This works well in Linux, but in Windows it is always the name of the current executable (from GetModuleFileNameW). This is because the 2 files Modules/getpath.c and PC/getpathp.c have completely different logic in calculate_program_full_path() vs get_program_full_path(). This difference is harmless when running in the normal interpreter (python.exe), but can be quite dramatic when embedding python into a C application. The value returned by Py_GetProgramFullPath() is the same as sys.executable in python. Why this matters? For instance in Linux virtual environments work out of the box for embedded applications, while they are completely ignored in Windows. python -m venv abcd and then if I run my app inside the (activated) abcd environment in Linux I can access the same modules as if I were executing python, while in Windows I still get the system module search path. If you execute the attached program in Linux you get EXECUTABLE /tmp/abcd/bin/python3 PATH ['/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/tmp/abcd/lib/python3.7/site-packages'] in Windows EXECUTABLE c:\TEMP\vsprojects\ConsoleApplication1\x64\Release\ConsoleApplication1.exe PATH ['C:\\TEMP\\venv\\abcd\\Scripts\\python37.zip', 'C:\\Python37\\Lib', 'C:\\Python37\\DLLs', 'c:\\TEMP\\vsprojects\\ConsoleApplication1\\x64\\Relea se', 'C:\\Python37', 'C:\\Python37\\lib\\site-packages'] with a mixture of paths from the venv, system and my app folder. But more importantly site-packages comes from the system (bad!). This is because site.py at lines 454 uses the path of the interpreter to locate the venv configuration file. So in the end, virtual environments work out of the box in Linux even for an embedded python, but not in Windows. ---------- components: Interpreter Core, Windows files: poc.c messages: 325666 nosy: mariofutire, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: Py_GetProgramFullPath() odd behaviour in Windows versions: Python 3.6, Python 3.7 Added file: https://bugs.python.org/file47814/poc.c _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34725> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com