importing packages from a zip file

Peter Tillotson none at no.chance
Wed Jun 29 14:43:44 EDT 2005


solution: have to add the zip archives to the PYTHONPATH, can be done in
the env but also as below

import sys, os.path
zipPackages=['base.zip']
for package in zipPackages:
    sys.path.insert(0,os.path.join(sys.path[0],package))

import base.branch1.myModule

Peter Tillotson wrote:
> Hi all,
> 
> I was wondering if this is possible. In python v2.3 the import systems
> was extended via PEP302 to cope with packages. *.py files in a directory
> hierarchy can be imported as modules each level in the directory
> hierarchy needs to contain at least an empty __init__.py file.
> 
> eg. With the file system
> 
> base/
> __init__.py
>     branch1/
>     __init__.py
>     myModule.py
> 
> I can import myModule as follows
> 
> import base.branch1.myModule
> 
> At the same time its possible to store modules in a flat zip-file and
> import modules with the following.
> 
> from myZip.zip import myModule.py
> 
> but is there a way to do both at the same time? eg.
> 
> from myZip.zip import base.branch1.myModule
> 
> I'm interested in this in the development of mobile code for some Grid
> applications :-)
> 
> thanks in advance
> 
> p



More information about the Python-list mailing list