Creating Zip file like java jar file

Discussion in 'Python' started by zaheer.agadi@gmail.com, Feb 28, 2009.

  1. Guest

    Hi,
    I want to create zip file equivalent to java jar file,I created a zip
    file of my sources and added some __main__.py
    some how I am getting an error saying __main.py does not exist in the
    zip file

    Copyproject(main folder)
    |
    |_____src(folder)
    | |
    | |__Nertworkpackage
    | | |
    | | |__Storepackage
    | | |
    | |__FtpPackage |__module1.py
    | |__module2.py
    |____ tests |__ module3.py

    Copyproject(main folder) | |_____src(folder) | | | |__Nertworkpackage
    | | | | | |__Storepackage | | | | |__FtpPackage |__module1.py | |
    __module2.py |____ tests |__ module3.py

    Module1 takes some commandline parameters that will do some operation
    Like If I say
    " module1.py --uploadFile <file name> " A file should get uploaded
    (this works)
    Now I want to do
    Copyproject.zip --uploadFile <filename> to upload the file

    How should I do this, I tried to put __main__ parallel to src folder
    it says __Main__.py not found in Copyproject.zip..?
    , Feb 28, 2009
    #1
    1. Advertising

  2. En Sat, 28 Feb 2009 14:34:15 -0200, <> 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..?


    __main__.py must exist in the root directory.

    --
    Gabriel Genellina
    Gabriel Genellina, Feb 28, 2009
    #2
    1. Advertising

  3. Guest

    On Feb 28, 11:15 pm, "Gabriel Genellina" <>
    wrote:
    > En Sat, 28 Feb 2009 14:34:15 -0200, <> 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..?

    >
    > __main__.py must exist in the root directory.
    >
    > --
    > Gabriel Genellina


    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..?
    , Feb 28, 2009
    #3
  4. Lie Ryan Guest

    wrote:
    > On Feb 28, 11:15 pm, "Gabriel Genellina" <>
    > wrote:
    >> En Sat, 28 Feb 2009 14:34:15 -0200, <> 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..?

    >> __main__.py must exist in the root directory.
    >>
    >> --
    >> Gabriel Genellina

    >
    > 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.
    Lie Ryan, Feb 28, 2009
    #4
  5. Lie Ryan Guest

    wrote:
    > On Feb 28, 11:15 pm, "Gabriel Genellina" <>
    > wrote:
    >> En Sat, 28 Feb 2009 14:34:15 -0200, <> 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..?

    >> __main__.py must exist in the root directory.
    >>
    >> --
    >> Gabriel Genellina

    >
    > 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.
    Lie Ryan, Feb 28, 2009
    #5
  6. Guest

    On Feb 28, 11:33 pm, Lie Ryan <> wrote:
    > wrote:
    > > On Feb 28, 11:15 pm, "Gabriel Genellina" <>
    > > wrote:
    > >> En Sat, 28 Feb 2009 14:34:15 -0200, <> 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..?
    > >> __main__.py must exist in the root directory.

    >
    > >> --
    > >> Gabriel Genellina

    >
    > > 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
    getting
    python.exe cannot find __main__.py in CopyProject.zip

    I used the following command
    python Copyproject.zip -m __main__.py --uploadFile and also tried with
    python Copyproject.zip --uploadFile
    both give me the same error , I can see the sys.path contains the
    project folder.
    , Feb 28, 2009
    #6
  7. En Sat, 28 Feb 2009 16:51:04 -0200, <> escribió:
    > On Feb 28, 11:33 pm, Lie Ryan <> wrote:
    >> wrote:
    >> > On Feb 28, 11:15 pm, "Gabriel Genellina" <>
    >> > wrote:
    >> >> En Sat, 28 Feb 2009 14:34:15 -0200, <>

    >> 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..?
    >> >> __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
    > getting
    > 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")
    z.printdir()

    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.


    Uh? Which project folder? Isn't it in the .zip?

    --
    Gabriel Genellina
    Gabriel Genellina, Feb 28, 2009
    #7
  8. Guest

    wrote:
    > On Feb 28, 11:33 pm, Lie Ryan <> wrote:
    > > wrote:
    > > > On Feb 28, 11:15 pm, "Gabriel Genellina" <>
    > > > wrote:
    > > >> En Sat, 28 Feb 2009 14:34:15 -0200, <> escribi=

    > =F3:
    > >
    > > >>> 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..?
    > > >> __main__.py must exist in the root directory.

    > >
    > > >> --
    > > >> Gabriel Genellina

    > >
    > > > 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 getting
    > python.exe cannot find __main__.py in CopyProject.zip
    >
    > I used the following command
    > python Copyproject.zip -m __main__.py --uploadFile and also tried with
    > python Copyproject.zip --uploadFile
    > both give me the same error , I can see the sys.path contains the
    > project folder.


    How did you create the zip? The __main__.py file has to be at the
    _top level_ of the zip file. In other words:

    zip test.zip __main.py othermodule.py somedir

    works but

    zip test.zip myproject

    does not.

    --RDM
    , Feb 28, 2009
    #8
  9. Guest

    On Mar 1, 1:32 am, "Gabriel Genellina" <> wrote:
    > En Sat, 28 Feb 2009 16:51:04 -0200, <> escribió:
    >
    >
    >
    > > On Feb 28, 11:33 pm, Lie Ryan <> wrote:
    > >> wrote:
    > >> > On Feb 28, 11:15 pm, "Gabriel Genellina" <>
    > >> > wrote:
    > >> >> En Sat, 28 Feb 2009 14:34:15 -0200, <>
    > >> 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..?
    > >> >> __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
    > > getting
    > > 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")
    > z.printdir()
    >
    > 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__)),
    "somezip.zip"))

    import zipfile
    z = zipfile.ZipFile("somezip.zip")
    z.printdir()

    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..?
    , Mar 1, 2009
    #9
  10. Steve Holden Guest

    wrote:
    > On Mar 1, 1:32 am, "Gabriel Genellina" <> wrote:
    >> En Sat, 28 Feb 2009 16:51:04 -0200, <> escribió:
    >>
    >>
    >>
    >>> On Feb 28, 11:33 pm, Lie Ryan <> wrote:
    >>>> wrote:
    >>>>> On Feb 28, 11:15 pm, "Gabriel Genellina" <>
    >>>>> wrote:
    >>>>>> En Sat, 28 Feb 2009 14:34:15 -0200, <>
    >>>> 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..?
    >>>>>> __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
    >>> getting
    >>> 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")
    >> z.printdir()
    >>
    >> 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__)),
    > "somezip.zip"))
    >
    > import zipfile
    > z = zipfile.ZipFile("somezip.zip")
    > z.printdir()
    >
    > 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?

    regards
    Steve
    --
    Steve Holden +1 571 484 6266 +1 800 494 3119
    Holden Web LLC http://www.holdenweb.com/
    Steve Holden, Mar 1, 2009
    #10
  11. En Sun, 01 Mar 2009 03:16:53 -0200, <> 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 Genellina
    Gabriel Genellina, Mar 1, 2009
    #11
  12. Guest

    On Mar 1, 6:53 pm, "Gabriel Genellina" <> wrote:
    > En Sun, 01 Mar 2009 03:16:53 -0200, <> 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
    , Mar 1, 2009
    #12
  13. Guest

    On Mar 1, 7:40 pm, wrote:
    > On Mar 1, 6:53 pm, "Gabriel Genellina" <> wrote:
    >
    >
    >
    > > En Sun, 01 Mar 2009 03:16:53 -0200, <> 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,
    , Mar 1, 2009
    #13
  14. Guest

    On Mar 1, 7:53 pm, wrote:
    > On Mar 1, 7:40 pm, wrote:
    >
    >
    >
    > > On Mar 1, 6:53 pm, "Gabriel Genellina" <> wrote:

    >
    > > > En Sun, 01 Mar 2009 03:16:53 -0200, <> 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,


    Thanks a lot folks it is solved now,the problem was I had to create a
    zip file from the location where actual package declarations are there
    and not from the top level directory whatever I had.
    I created zip file from the src directory of the my tree which had all
    the packages as its next level contents and imports were resolved.
    , Mar 1, 2009
    #14
  15. En Sun, 01 Mar 2009 12:53:30 -0200, <> escribió:
    > On Mar 1, 7:40 pm, wrote:
    >> On Mar 1, 6:53 pm, "Gabriel Genellina" <> wrote:
    >> > En Sun, 01 Mar 2009 03:16:53 -0200, <> 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


    >> 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


    So the __main__.py is recognized and runs. That's good news. But I see
    *another* __main__.py listed that should not exist, in a directory BRU.
    Are you sure you tested using the *outer* __main__.py? And what is that
    __init__.py?

    Test in *another* directory, not your development environment, and remove
    all those extra artifacts like .svn directories and such that you're not
    going to deploy, I presume.

    > 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 see "network" inside "src" in your directory tree. For something like
    "ipmort network.storage" to work, "src" must be in the import path used by
    Python (sys.path).

    > I appreciate your help Gabriella thanks a lot,


    My name is *Gabriel* and I'm male...

    --
    Gabriel Genellina
    Gabriel Genellina, Mar 1, 2009
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnold Peters
    Replies:
    0
    Views:
    564
    Arnold Peters
    Jan 5, 2005
  2. Lee
    Replies:
    4
    Views:
    21,484
    Roedy Green
    Feb 13, 2006
  3. cyberco
    Replies:
    4
    Views:
    3,747
    Roedy Green
    Feb 14, 2006
  4. Replies:
    5
    Views:
    907
    Roedy Green
    Apr 6, 2006
  5. m.niinimaki
    Replies:
    9
    Views:
    1,066
    steph
    Aug 29, 2010
Loading...

Share This Page