On Fri, Oct 3, 2014 at 5:33 PM, Zachary Turner <ztur...@google.com> wrote: > Also, to answer your the question more specifically about sys.path, when I > run my debug build of python_d.exe from the commandl ine and print sys.path > I get this: > >>>> sys.path > ['', 'D:\\python_src\\Python-2.7.8\\Lib', > 'D:\\src\\llvm\\build\\ninja\\lib\\site-packages', > 'd:\\python_src\\Python-2.7.8\\pcbuild\\python27_d.zip', > 'd:\\python_src\\Python-2.7.8\\DLLs', > 'd:\\python_src\\Python-2.7.8\\lib\\plat-win', > 'd:\\python_src\\Python-2.7.8\\lib\\lib-tk', > 'd:\\python_src\\Python-2.7.8\\pcbuild', 'd:\\python_src\\Python-2.7.8', > 'd:\\python_src\\Python-2.7.8\\lib\\site-packages'] > [43489 refs] > > When I do the same thing from my embedded interpreter, I get this: > ['D:\\src\\llvm\x08uild\ninja\x08in', > 'D:\\src\\llvm\x08uild\ninja\x08in\\..\\lib\\site-packages', > 'D:\\python_src\\Python-2.7.8\\Lib', > 'D:\\src\\llvm\\build\\ninja\\lib\\site-packages', > 'D:\\python_src\\Python-2.7.8\\PCbuild\\python27_d.zip', > 'C:\\Python27\\Lib', 'C:\\Python27\\DLLs', 'C:\\Python27\\Lib\\lib-tk', > 'D:\\src\\llvm\\build\\ninja', 'D:\\src\\llvm\\build\\ninja\\bin', > 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', '.'] > > The first two junked up entries are bugs I need to fix, but not relevant > really to this. It's worth noting that > d:\\python_src\\Python-2.7.8\\pcbuild is not included. That's probably > where the problem lies. Both of these were run with the same system > environment, so there's no difference there. Someone running python_d.exe > gets d:\\python_src\\Python-2.7.8\\pcbuild in sys.path, but linking against > the DLL doesn't.
I will note that I haven't done any embedding of Python myself, so I'm shooting in the dark a little bit here. From what I've read trying to figure this out (and from other background information picked up over the past few years), the default setting of sys.path is an unholy mess. Some values are defaults based on the value of sys.prefix (or sys.exec_prefix, both of which are based on sys.executable, set by Py_SetProgramName), values can come from the environment (PYTHONPATH), and on Windows, values can even come from the registry (which is where C:\Python27\* came from in your embedded interpreter). sys.path is manipulated by Py_Initialize, PySys_SetArgv, and site.py (usually in that order, I think). And the rules also change on Windows when python(_d).exe detects that it's in a build directory rather than an installed location. I think your best solution here might be to just set sys.path yourself (https://docs.python.org/2/c-api/sys.html#c.PySys_SetPath) just after Py_Initialize, overwriting the default values. This also gives you the added benefit of being able to put the Python libraries (Lib/**.py and PCbuild/*.pyd) wherever you want them (even in the same folder, or even a zipfile), rather than trying to fit them into where Python expects them to be, and you don't run the risk of running Python code that really probably shouldn't have been findable anyway. Hope this is of some help, -- Zach _______________________________________________ python-win32 mailing list python-win32@python.org https://mail.python.org/mailman/listinfo/python-win32