Creating Zip file like java jar file

zaheer.agadi at gmail.com zaheer.agadi at gmail.com
Sun Mar 1 15:53:30 CET 2009


On Mar 1, 7:40 pm, zaheer.ag... at gmail.com wrote:
> 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

and also what it gives me when I Do, > python BRU.zip
some list of files
:
:
BRU/__init__.py                                2009-02-28
17:08:10          1
BRU/__main__.py                                2009-03-01
18:17:20          8
BRU/                                           2009-03-01 14:52:58
Traceback (most recent call last):
  File "C:\Python26\lib\runpy.py", line 121, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python26\lib\runpy.py", line 34, in _run_code
    exec code in run_globals
  File "BRU.zip\__main__.py", line 18, in <module>
ImportError: No module named network.storage

I think I should I also mention I create this application using
ecliplse plugin

I appreciate your help Gabriella thanks  a lot,



More information about the Python-list mailing list