Re: embedded python pythonpath
On Wed, Mar 26, 2008 at 3:49 AM, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 25 Mar 2008 22:22:41 -0300, Furkan Kuru [EMAIL PROTECTED] escribió: On 3/26/08, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 25 Mar 2008 20:38:39 -0300, Furkan Kuru [EMAIL PROTECTED] escribió: Actually, I do not want any .py or .pyc files around my executable. (including userdict, sys, site etc) I want to have just single zip file for all python files. Putting all of them into pythonNN.zip (NN depending on the Python version in use) should be enough, but I've never tried it. I had already tried putting all of them into pythonNN.zip but I had to copy it to the place where sys.path points in my case it was windows\system32\python25.zip It should be in the same directory as python25.dll; you don't have to use windows\system32 if you copy python25.dll to your application directory. I did not know that. Ok, I tried and it works! Thank you, -- Furkan Kuru -- http://mail.python.org/mailman/listinfo/python-list
Re: embedded python pythonpath
Furkan Kuru furkankuru at gmail.com writes: I've tried below code (Setting pythonpath environment variable) and then initialize python interpreter but the embedded python interpreter did not get the newly assigned PYTHONPATH. I ve looked at the sys.path in python code (that is run by the embedded interpreter) and it behaved according to older pythonpath. Note that you don't HAVE to set the environment variable PYTHONPATH, there are other ways to get directories listed in sys.path - and that is what really counts. The simplest way is to just write code to insert the desired directories in front of sys.path, after the call to Py_Initialize. The only problem is that some modules (like site and sitecustomize) are searched and executed before your code has a chance to modify sys.path - I hope it's not a problem for you. Setting environment variable seemed to be correct. Does py_initialize run in another thread so it starts before setting the environment var? I could reproduce the problem with a smaller code (using C, not C++). Testing with Python 2.5.1 doesn't work (that means, it ignores the new setting for PYTHONPATH). Testing with current Python trunk (from svn) *does* work. I don't know if this is a bug that has been fixed, or it works that way because the svn version is not the default installation and then searches for things in a different way. #include Python.h int main(int argc, char *argv[]) { putenv(PYTHONPATH=C:\\TEMP\\MF); system(set PYTHONPATH); printf(Py_GETENV(PYTHONPATH)=%s\n, Py_GETENV(PYTHONPATH)); Py_Initialize(); PyRun_SimpleString(import sys\nprint sys.path); Py_Finalize(); return 0; } I compiled twice with these commands: cl -MD -Ic:\apps\python25\include test.c c:\apps\python25 \Libs\Python25.lib /Fetest25.exe cl -MD -Ic:\apps\python\trunk\PC -Ic:\apps\python\trunk\include test.c c:\apps\python\trunk\PCbuild\Python26.lib /Fetest26.exe Python25.dll and Python26.dll both were copied into the current directory. test25.exe: PYTHONPATH=C:\TEMP\MF Py_GETENV(PYTHONPATH)=C:\TEMP\MF ['C:\\Apps\\Python25\\lib\\site-packages\\setuptools-0.6c5- py2.5.egg', 'C:\\Apps\\Python25\\lib\\site-packages\\ simplejson-1.7.1-py2.5-win32.egg', ... many directories, not including C:\TEMP\MF ... ] test26.exe: PYTHONPATH=C:\TEMP\MF Py_GETENV(PYTHONPATH)=C:\TEMP\MF 'import site' failed; use -v for traceback ['C:\\TEMP\\MF', 'C:\\TEMP\\python26.zip', '', 'C:\\TEMP'] I don't understand how the test program, compiled for 2.5.1, could actually locate the Python directory. (It's not in my PATH, it's not the default install directory, and I deleted the HKLM\Software\Python\PythonCore\2.5 registry key). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: embedded python pythonpath
Actually, I do not want any .py or .pyc files around my executable. (including userdict, sys, site etc) I want to have just single zip file for all python files. I had a look at py2exe source codes but could not figure out how it just looks into a zip file. So maybe I have to compile the svn version of python. On 3/26/08, Gabriel Genellina [EMAIL PROTECTED] wrote: Furkan Kuru furkankuru at gmail.com writes: I've tried below code (Setting pythonpath environment variable) and then initialize python interpreter but the embedded python interpreter did not get the newly assigned PYTHONPATH. I ve looked at the sys.path in python code (that is run by the embedded interpreter) and it behaved according to older pythonpath. Note that you don't HAVE to set the environment variable PYTHONPATH, there are other ways to get directories listed in sys.path - and that is what really counts. The simplest way is to just write code to insert the desired directories in front of sys.path, after the call to Py_Initialize. The only problem is that some modules (like site and sitecustomize) are searched and executed before your code has a chance to modify sys.path - I hope it's not a problem for you. Setting environment variable seemed to be correct. Does py_initialize run in another thread so it starts before setting the environment var? I could reproduce the problem with a smaller code (using C, not C++). Testing with Python 2.5.1 doesn't work (that means, it ignores the new setting for PYTHONPATH). Testing with current Python trunk (from svn) *does* work. I don't know if this is a bug that has been fixed, or it works that way because the svn version is not the default installation and then searches for things in a different way. #include Python.h int main(int argc, char *argv[]) { putenv(PYTHONPATH=C:\\TEMP\\MF); system(set PYTHONPATH); printf(Py_GETENV(PYTHONPATH)=%s\n, Py_GETENV(PYTHONPATH)); Py_Initialize(); PyRun_SimpleString(import sys\nprint sys.path); Py_Finalize(); return 0; } I compiled twice with these commands: cl -MD -Ic:\apps\python25\include test.c c:\apps\python25 \Libs\Python25.lib /Fetest25.exe cl -MD -Ic:\apps\python\trunk\PC -Ic:\apps\python\trunk\include test.c c:\apps\python\trunk\PCbuild\Python26.lib /Fetest26.exe Python25.dll and Python26.dll both were copied into the current directory. test25.exe: PYTHONPATH=C:\TEMP\MF Py_GETENV(PYTHONPATH)=C:\TEMP\MF ['C:\\Apps\\Python25\\lib\\site-packages\\setuptools-0.6c5- py2.5.egg', 'C:\\Apps\\Python25\\lib\\site-packages\\ simplejson-1.7.1-py2.5-win32.egg', ... many directories, not including C:\TEMP\MF ... ] test26.exe: PYTHONPATH=C:\TEMP\MF Py_GETENV(PYTHONPATH)=C:\TEMP\MF 'import site' failed; use -v for traceback ['C:\\TEMP\\MF', 'C:\\TEMP\\python26.zip', '', 'C:\\TEMP'] I don't understand how the test program, compiled for 2.5.1, could actually locate the Python directory. (It's not in my PATH, it's not the default install directory, and I deleted the HKLM\Software\Python\PythonCore\2.5 registry key). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- Furkan Kuru -- http://mail.python.org/mailman/listinfo/python-list
Re: embedded python pythonpath
En Tue, 25 Mar 2008 20:38:39 -0300, Furkan Kuru [EMAIL PROTECTED] escribió: Actually, I do not want any .py or .pyc files around my executable. (including userdict, sys, site etc) I want to have just single zip file for all python files. Putting all of them into pythonNN.zip (NN depending on the Python version in use) should be enough, but I've never tried it. I had a look at py2exe source codes but could not figure out how it just looks into a zip file. Standard Python already supports having zip files in sys.path (using the builtin zipimport module), you don't have to do anything special to enable that (apart from building with the required dependencies, like zlib, of course) So maybe I have to compile the svn version of python. After renaming the directory where Python 2.5 were installed, my test25.exe program (the one compiled using Python 2.5.1) worked fine. So it looks like it is something with how the python home is searched. Anyway, as I said earlier, you don't have to play with PYTHONPATH; just add any required directory to sys.path at runtime. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: embedded python pythonpath
On 3/26/08, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 25 Mar 2008 20:38:39 -0300, Furkan Kuru [EMAIL PROTECTED] escribió: Actually, I do not want any .py or .pyc files around my executable. (including userdict, sys, site etc) I want to have just single zip file for all python files. Putting all of them into pythonNN.zip (NN depending on the Python version in use) should be enough, but I've never tried it. I had already tried putting all of them into pythonNN.zip but I had to copy it to the place where sys.path points in my case it was windows\system32\python25.zip I had a look at py2exe source codes but could not figure out how it just looks into a zip file. Standard Python already supports having zip files in sys.path (using the builtin zipimport module), you don't have to do anything special to enable that (apart from building with the required dependencies, like zlib, of course) yes I know but I do not want any py or pyc file. I would still need dict.pyc, sys.pyc, site.pyc etc. files for py_initialize. So maybe I have to compile the svn version of python. After renaming the directory where Python 2.5 were installed, my test25.exe program (the one compiled using Python 2.5.1) worked fine. So it looks like it is something with how the python home is searched. Ok then changing or deleting pythonhome environment variable may fix the problem? thanks, Anyway, as I said earlier, you don't have to play with PYTHONPATH; just add any required directory to sys.path at runtime. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list -- Furkan Kuru -- http://mail.python.org/mailman/listinfo/python-list
Re: embedded python pythonpath
En Tue, 25 Mar 2008 22:22:41 -0300, Furkan Kuru [EMAIL PROTECTED] escribió: On 3/26/08, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 25 Mar 2008 20:38:39 -0300, Furkan Kuru [EMAIL PROTECTED] escribió: Actually, I do not want any .py or .pyc files around my executable. (including userdict, sys, site etc) I want to have just single zip file for all python files. Putting all of them into pythonNN.zip (NN depending on the Python version in use) should be enough, but I've never tried it. I had already tried putting all of them into pythonNN.zip but I had to copy it to the place where sys.path points in my case it was windows\system32\python25.zip It should be in the same directory as python25.dll; you don't have to use windows\system32 if you copy python25.dll to your application directory. After renaming the directory where Python 2.5 were installed, my test25.exe program (the one compiled using Python 2.5.1) worked fine. So it looks like it is something with how the python home is searched. Ok then changing or deleting pythonhome environment variable may fix the problem? Python home means the directory where Python is installed, from which the rest of the directories are derived. It should have a lib directory with an os.py file inside, and so on... I don't have a PYTHONHOME environment variable, nor a PYTHONPATH (except for this testing). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list