Embedding Python's library as zip file

Wojtek Mamrak tacyt1007 at gmail.com
Thu May 5 16:34:02 EDT 2011


> That means it's not finding it.  After startup, try adding the zip
> file to your sys.path and then do "import site" at the command line,
> and it should work.

Maybe I am missing the point, but I think I am not able to do this.
When I remove the "Lib" folder and try to run Python.exe, the python
console window closes rapidly, so that it is hard to read any message
displayed in it and obvioulsy I can't run any python command. Could
you clarify this please?


> What if you put the zip file in your
> PYTHONPATH environment variable?

I don't have it defined. Maybe it is because I have 2 different Python
interpreters installed.
After adding the PYTHONPATH, the Python.exe seems to run normally.
Unfortunately I am not able to import Image module (I am using it),
which is installed in site-packages/PIL.
This happens, because for some reason the site-packages directory is
not present in sys.path. After reading the site module description I
checked the sys.prefix and sys.exec_prefix, which are both empty, when
the Lib folder is loaded from the zip archive. Thats why site-packages
is not added to sys.path.
Of course I can add site-packages directory to the sys.path by myself
(yet I don't know why sys.prefix and sys.exec_prefix are empty),
however how to deal with the PYTHONPATH, which is required to load
site.py and hence has to be defined at the very beginning?


thanks for your help


2011/5/5 Ian Kelly <ian.g.kelly at gmail.com>:
> On Thu, May 5, 2011 at 4:55 AM, Wojtek Mamrak <tacyt1007 at gmail.com> wrote:
>> Thanks for the reply!
>>
>>> Can you import from zip files when running the Python.exe interpreter?
>> When I zip the folder "Lib" into Python27.zip and later rename it and
>> try to run the python.exe, I receive an error:
>> "Import error: no module named site"
>
> That means it's not finding it.  After startup, try adding the zip
> file to your sys.path and then do "import site" at the command line,
> and it should work.
>
>>> Are you getting any sort of error message?
>> When I run my app, it crashes while calling Py_Initialize(). The
>> console closes suddenly.
>
> Hm, that definitely seems odd.  What if you put the zip file in your
> PYTHONPATH environment variable?
>
>> Is it necessary to create zip archive using zipfile.PyZipFile?
>
> It shouldn't be.  It works for me (at least with Python.exe) creating
> the zip archive using 7-Zip.
>



More information about the Python-list mailing list