Py2exe embed my modules to libary.zip

V

vedrandekovic

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
 
G

Gabriel Genellina

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

vedrandekovic

En Wed, 26 Mar 2008 15:38:16 -0300, Tzury Bar Yochay



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"

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
 
G

Gabriel Genellina

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']
 
V

vedrandekovic

En Thu, 27 Mar 2008 06:00:26 -0300, <[email protected]> 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']

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
 
G

Gabriel Genellina

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top