Creating Zip file like java jar file
steve at holdenweb.com
Sun Mar 1 14:31:45 CET 2009
zaheer.agadi at gmail.com wrote:
> On Mar 1, 1:32 am, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
>> En Sat, 28 Feb 2009 16:51:04 -0200, <zaheer.ag... at gmail.com> escribió:
>>> On Feb 28, 11:33 pm, Lie Ryan <lie.1... at gmail.com> wrote:
>>>> zaheer.ag... at gmail.com wrote:
>>>>> On Feb 28, 11:15 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
>>>>>> En Sat, 28 Feb 2009 14:34:15 -0200, <zaheer.ag... at gmail.com>
>>>>>>> I want to create zip file equivalent to java jar file,I created a
>>>>>>> file of my sources and added some __main__.py
>>>>>>> it says __Main__.py not found in Copyproject.zip..?
>>>>>> __main__.py must exist in the root directory.
>>>>> What do you mean by root directory..?What is this directory in
>>>>> Windows..?You mean the top level folder of the project?in my case
>>>>> copyproject folder..?
>>>> root directory is the topmost directory (imagine a tree, the root is
>>>> where all the branches branched from), in this case the root directory
>>>> is your copyproject main folder.
>>> I wonder, I do have the __main__.py in the root directory,but still
>>> python.exe cannot find __main__.py in CopyProject.zip
>> The top of the tree inside the zip file. Depth zero. Not inside any
>> directory. Above anything else. Just a bare name.
>> Open your zip using the zipfile module:
>> import zipfile
>> z = zipfile.ZipFile("xxx.zip")
>> You should see a line starting with __main__.py *without* any / in it.
>>> I used the following command
>>> python Copyproject.zip -m __main__.py --uploadFile and also tried with
>>> python Copyproject.zip --uploadFile
>> Use the second one.
>>> both give me the same error , I can see the sys.path contains the
>>> project folder.
>> Gabriel Genellina
>> Uh? Which project folder? Isn't it in the .zip?
> Yeah I meant zip file.
> I can get to work but is it is not able to locate the packages,says
> import error cant find the package and module
> here is my code
> import sys
> import os.path as op
> sys.path.insert(0, op.join(op.dirname(op.abspath(__file__)),
> import zipfile
> z = zipfile.ZipFile("somezip.zip")
> import some.storagepackage.somemodule
> print "upload"
> print "syspath",sys.path
> #do something
> should it not find the modules when the zip files is in sys.path..?
For this to work not only should your zipfile contain
some/storagepackage/somemodule.py, but some and some/storagepackage must
both contain __init__.py files to be recognized as packages.
Have you tried getting your imports working from the file store and then
zipping up what works afterwards?
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list