Py2exe embed my modules to libary.zip

Discussion in 'Python' started by vedrandekovic@gmail.com, Mar 26, 2008.

  1. Guest

    Hello,

    Does anybody have any idea how can I embed my modules to libary.zip
    and use it from my application.For example if user write this code in
    my TextEntry ( or something like that, textentry is created with
    wxpython ) :

    import d3dx # directpython module
    frame=d3dx.Frame(u"My frame") # create frame
    frame.Mainloop() # run it

    .....and then when my application execute code how can I set path to
    d3dx module to "library.zip/d3dx.py".
    I'm not sure is this properly set question.

    Regards,
    Vedran
     
    , Mar 26, 2008
    #1
    1. Advertising

  2. En Wed, 26 Mar 2008 14:55:43 -0300, <> escribió:

    > Does anybody have any idea how can I embed my modules to libary.zip
    > and use it from my application.For example if user write this code in
    > my TextEntry ( or something like that, textentry is created with
    > wxpython ) :
    >
    > import d3dx # directpython module
    > frame=d3dx.Frame(u"My frame") # create frame
    > frame.Mainloop() # run it
    >
    > ....and then when my application execute code how can I set path to
    > d3dx module to "library.zip/d3dx.py".
    > I'm not sure is this properly set question.


    If d3dx.py is in library.zip (top level), and the path to library.zip is
    in sys.path, Python will find the module.
    A .zip in sys.path acts as it were a directory itself.

    --
    Gabriel Genellina
     
    Gabriel Genellina, Mar 26, 2008
    #2
    1. Advertising

  3. Tzury Bar Yochay, Mar 26, 2008
    #3
  4. En Wed, 26 Mar 2008 15:38:16 -0300, Tzury Bar Yochay
    <> escribió:

    >> ....and then when my application execute code how can I set path to
    >> d3dx module to "library.zip/d3dx.py".
    >> I'm not sure is this properly set question.

    >
    > use the module zipimport
    > http://docs.python.org/lib/module-zipimport.html


    You don't have to do anything special to "use" zipimport; from
    <http://docs.python.org/lib/module-zipimport.html> :
    "It is usually not needed to use the zipimport module explicitly; it is
    automatically used by the builtin import mechanism"

    --
    Gabriel Genellina
     
    Gabriel Genellina, Mar 26, 2008
    #4
  5. Guest

    On 26 ožu, 20:11, "Gabriel Genellina" <> wrote:
    > En Wed, 26 Mar 2008 15:38:16 -0300, Tzury Bar Yochay
    > <> escribió:
    >
    > >> ....and then when my application execute code how can I set path to
    > >> d3dx module to "library.zip/d3dx.py".
    > >> I'm not sure is this properly set question.

    >
    > > use the module zipimport
    > >http://docs.python.org/lib/module-zipimport.html

    >
    > You don't have to do anything special to "use" zipimport; from
    > <http://docs.python.org/lib/module-zipimport.html> :
    > "It is usually not needed to use the zipimport module explicitly; it is
    > automatically used by the builtin import mechanism"
    >
    > --
    > Gabriel Genellina


    Hello,

    I was add this into my application code:

    import sys
    import os
    my_dir=os.getcwd()
    sys.path.append(my_dir)
    sys.path.append(my_dir+"\\libary.zip")
    sys.path.append(my_dir+"\\libary.zip\\py2exe") # PY2EXE is folder
    f=open("path.txt","w")
    f.write(str(sys.path))
    f.close()

    an the output in path.txt is :

    ['C:\\Users\\veki\\Desktop\\python\\PGS\\dist\\library.zip', 'C:\\Users
    \\veki\\Desktop\\python\\PGS\\dist', 'C:\\Users\\veki\\Desktop\\python\
    \PGS\\dist\\libary.zip', 'C:\\Users\\veki\\Desktop\\python\\PGS\\dist\
    \libary.zip\\py2exe']

    But it still can't find module py2exe.What should I do now? Any
    examples?

    Regards,
    Vedran
     
    , Mar 27, 2008
    #5
  6. En Thu, 27 Mar 2008 06:00:26 -0300, <> escribió:

    > I was add this into my application code:
    >
    > import sys
    > import os
    > my_dir=os.getcwd()
    > sys.path.append(my_dir)
    > sys.path.append(my_dir+"\\libary.zip")
    > sys.path.append(my_dir+"\\libary.zip\\py2exe") # PY2EXE is folder
    > f=open("path.txt","w")
    > f.write(str(sys.path))
    > f.close()
    >
    > an the output in path.txt is :
    >
    > ['C:\\Users\\veki\\Desktop\\python\\PGS\\dist\\library.zip', 'C:\\Users
    > \\veki\\Desktop\\python\\PGS\\dist', 'C:\\Users\\veki\\Desktop\\python\
    > \PGS\\dist\\libary.zip', 'C:\\Users\\veki\\Desktop\\python\\PGS\\dist\
    > \libary.zip\\py2exe']
    >
    > But it still can't find module py2exe.What should I do now? Any
    > examples?


    I assume you're talking about the py2exe package available from
    www.py2exe.org - so it's not a module, it's a package.
    py2exe usually is only relevant on your *development* machine, so why do
    you want to put it inside a .zip? What do you want to do?

    Anyway, I tried the following and could import py2exe successully (but I
    don't know if it actually works as a distutils extension...)

    - compressed the py2exe folder into py2exe.zip
    - deleted the original py2exe folder
    - moved py2exe.zip onto some temporary directory
    - tried to import py2exe, failed as expected
    - added py2exe.zip to sys.path
    - tried to import py2exe, this time OK

    py> import py2exe
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: No module named py2exe
    py> import sys
    py> sys.path.append(r"C:\TEMP\pna\py2exe.zip")
    py> import py2exe
    py> py2exe.__path__
    ['C:\\TEMP\\pna\\py2exe.zip\\py2exe']

    --
    Gabriel Genellina
     
    Gabriel Genellina, Mar 27, 2008
    #6
  7. Guest

    On 27 ožu, 10:44, "Gabriel Genellina" <> wrote:
    > En Thu, 27 Mar 2008 06:00:26 -0300, <> escribió:
    >
    >
    >
    > > I was add this into my application code:

    >
    > > import sys
    > > import os
    > > my_dir=os.getcwd()
    > > sys.path.append(my_dir)
    > > sys.path.append(my_dir+"\\libary.zip")
    > > sys.path.append(my_dir+"\\libary.zip\\py2exe") # PY2EXE is folder
    > > f=open("path.txt","w")
    > > f.write(str(sys.path))
    > > f.close()

    >
    > > an the output in path.txt is :

    >
    > > ['C:\\Users\\veki\\Desktop\\python\\PGS\\dist\\library.zip', 'C:\\Users
    > > \\veki\\Desktop\\python\\PGS\\dist', 'C:\\Users\\veki\\Desktop\\python\
    > > \PGS\\dist\\libary.zip', 'C:\\Users\\veki\\Desktop\\python\\PGS\\dist\
    > > \libary.zip\\py2exe']

    >
    > > But it still can't find module py2exe.What should I do now? Any
    > > examples?

    >
    > I assume you're talking about the py2exe package available from www.py2exe.org- so it's not a module, it's a package.
    > py2exe usually is only relevant on your *development* machine, so why do
    > you want to put it inside a .zip? What do you want to do?
    >
    > Anyway, I tried the following and could import py2exe successully (but I
    > don't know if it actually works as a distutils extension...)
    >
    > - compressed the py2exe folder into py2exe.zip
    > - deleted the original py2exe folder
    > - moved py2exe.zip onto some temporary directory
    > - tried to import py2exe, failed as expected
    > - added py2exe.zip to sys.path
    > - tried to import py2exe, this time OK
    >
    > py> import py2exe
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > ImportError: No module named py2exe
    > py> import sys
    > py> sys.path.append(r"C:\TEMP\pna\py2exe.zip")
    > py> import py2exe
    > py> py2exe.__path__
    > ['C:\\TEMP\\pna\\py2exe.zip\\py2exe']
    >
    > --
    > Gabriel Genellina


    Hello again,

    Thanks for previous post, it was useful!

    So now I know what is a problem, but I don't know how to solve
    it.Under my application user can convert his python code to
    executable,
    I was created this with subprocess:

    retcode =subprocess.Popen(["ython","setup.py","py2exe","-d","exe"],
    shell=True, stdout=subprocess.PIPE,creationflags =
    win32process.CREATE_NO_WINDOW)
    stdout_value = retcode.communicate()[0]

    ...Py2exe exit from process here:

    running py2exe
    creating C:\Users\veki\Desktop\python\PGS\dist\build
    creating C:\Users\veki\Desktop\python\PGS\dist\build\bdist.win32
    creating C:\Users\veki\Desktop\python\PGS\dist\build
    \bdist.win32\winexe
    creating C:\Users\veki\Desktop\python\PGS\dist\build\bdist.win32\winexe
    \collect-2.5
    creating C:\Users\veki\Desktop\python\PGS\dist\build\bdist.win32\winexe
    \bundle-2.5
    creating C:\Users\veki\Desktop\python\PGS\dist\build\bdist.win32\winexe
    \temp
    creating C:\Users\veki\Desktop\python\PGS\dist\exe
    *** searching for required modules ***

    ...it's trying to find d3d,d3dx,d3dc,d3dgui... modules but it can't
    cause these modules are in library.zip.How can I set target for
    finding path to library.zip , I'm running these py2exe compile process
    from my main excutable?

    Regards,
    Vedran
     
    , Mar 27, 2008
    #7
  8. En Thu, 27 Mar 2008 14:34:02 -0300, Larry Bates <>
    escribió:

    > Create your py2exe distribution without a zipfile and all the modules
    > will just be put into the installation directory. Use Inno Setup to
    > make a proper installer for your application.


    I second that. It's the easiest way. Another way it to help improve py2exe
    so it can find modules from inside a .zip and extract them (if this
    happens to be the cause).

    --
    Gabriel Genellina
     
    Gabriel Genellina, Mar 27, 2008
    #8
    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. Steve Drake
    Replies:
    2
    Views:
    985
    Steve Drake
    Jun 16, 2004
  2. sam
    Replies:
    2
    Views:
    433
    Thierry Miceli
    May 17, 2005
  3. Ka
    Replies:
    10
    Views:
    705
    Richard Bos
    Jul 31, 2003
  4. Freefish

    A simple math libary problem?

    Freefish, Nov 17, 2003, in forum: C Programming
    Replies:
    10
    Views:
    546
    Mark McIntyre
    Nov 17, 2003
  5. Larry Bates
    Replies:
    0
    Views:
    1,442
    Larry Bates
    Mar 27, 2008
Loading...

Share This Page