Creating Zip file like java jar file

zaheer.agadi at gmail.com zaheer.agadi at gmail.com
Sun Mar 1 15:40:43 CET 2009


On Mar 1, 6:53 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Sun, 01 Mar 2009 03:16:53 -0200, <zaheer.ag... at gmail.com> escribió:
>
>
>
> >> >> >>> I want to create zip file equivalent to java jar file,I created a
> >> >> zip
> >> >> >>> file of my sources and added some __main__.py
> >> >> >>> it says __Main__.py not found in Copyproject.zip..?
> > I can get to work but is it is not able to locate the packages,says
> > import error cant find the package and module
>
> Make it work *before* you attempt to zip the files. A complete session:
>
> C:\TEMP>tree /a /f test_main_in_zip
> Listado de rutas de carpetas para el volumen Cucho
> El número de serie del volumen es 007A005F F4EC:16A9
> C:\TEMP\TEST_MAIN_IN_ZIP
> |   __main__.py
> |
> \---pkgA
>          foo.py
>          __init__.py
>
> C:\TEMP>cd test_main_in_zip
>
> C:\TEMP\test_main_in_zip>type __main__.py
> #!/bin/env python
>
> """This script is the entry point
> to the application"""
>
> import sys
> import pkgA.foo
>
> def main():
>    print "I'm main():"
>    print "__name__", __name__
>    print "__file__", __file__
>    print "sys.path", sys.path[:3], "..."
>    print
>    pkgA.foo.bar()
>
> main()
>
> C:\TEMP\test_main_in_zip>type pkgA\__init__.py
> print "I'm __init__.py"
> print "__name__",__name__
> print "__file__",__file__
> print
> C:\TEMP\test_main_in_zip>type pkgA\foo.py
> def bar():
>    print "I'm bar() inside foo.py:"
>    print "__name__",__name__
>    print "__file__",__file__
>    print
> C:\TEMP\test_main_in_zip>python __main__.py
> I'm __init__.py
> __name__ pkgA
> __file__ C:\TEMP\test_main_in_zip\pkgA\__init__.py
>
> I'm main():
> __name__ __main__
> __file__ __main__.py
> sys.path ['C:\\TEMP\\test_main_in_zip',
> 'c:\\apps\\python26\\python26.zip', 'c:\
> \apps\\python26\\DLLs'] ...
>
> I'm bar() inside foo.py:
> __name__ pkgA.foo
> __file__ C:\TEMP\test_main_in_zip\pkgA\foo.py
>
> C:\TEMP\test_main_in_zip>zip anyname.zip __main__.py pkgA\*
>    adding: __main__.py (196 bytes security) (deflated 40%)
>    adding: pkgA/foo.py (196 bytes security) (deflated 40%)
>    adding: pkgA/foo.pyc (196 bytes security) (deflated 41%)
>    adding: pkgA/__init__.py (196 bytes security) (deflated 38%)
>    adding: pkgA/__init__.pyc (196 bytes security) (deflated 29%)
>
> C:\TEMP\test_main_in_zip>python anyname.zip
> I'm __init__.py
> __name__ pkgA
> __file__ anyname.zip\pkgA\__init__.pyc
>
> I'm main():
> __name__ __main__
> __file__ None
> sys.path ['anyname.zip', 'c:\\apps\\python26\\python26.zip',
> 'c:\\apps\\python26
> \\DLLs'] ...
>
> I'm bar() inside foo.py:
> __name__ pkgA.foo
> __file__ anyname.zip\pkgA\foo.pyc
>
> --
> Gabriel Genellin

> Make it work *before* you attempt to zip the files.
  Thanks a lot Gabriel, yes this works fine when I am running it
outside of zip.
when I say  python __main__.py --uploadfile  it works fine
I dont know what happens when I zip it.

And Steve: all of the packages have __init__.py inside them, I have
posted the tree structure of application if it helps.

C:\DOCUMENTS AND SETTINGS\ADMINISTRATOR\DESKTOP\PYTHNSTUF
\TestApplication
├───src
│   ├───network
│   │   ├───.svn
│   │   │   └───text-base
│   │   └───storage
│   │       └───.svn
│   │           └───text-base
│   ├───uc
│   │   └───some
│   │       └───extra
│   │           └───package
│   └───webdav
│       └───acp
└───test
    └───.svn
        └───text-base




More information about the Python-list mailing list