py2exe excluding a module, and import it during runtime, how?

Thomas Heller theller at python.net
Wed May 5 12:20:35 EDT 2004


satya at ttck.keio.ac.jp (Satya Nanda Vel Arjunan) writes:

> Hi, I think there must be a simple solution for this problem, but I
> couldn't find any example of this problem when I searched for it. I am
> using py2exe-0.5.0. I would like to make a simple script, test.py into
> an exe file, test.exe. In test.py I import a custom module called emc:
[...]
> I would like to exclude the emc module when creating the exe file. To
> do this I used the following setup.py:
[...]
> When I run the test.exe I get the following error:
> ImportError: No module named emc
>
> I have tried putting the module emc.py in the same directory as
> test.exe and but it could not load it. So far I have only been
> successful if I include emc.py inside the library.zip file, which I do
> not want to do. How do we import a module only during runtime if we
> exclude it when creating the exe file? I need this feature because
> some modules are not readily available during the creation of the exe
> file. Thank you for any pointers.

This can be done, and I do it regularly.

You need to add the directory where your emc.py module is to sys.path,
by default the py2exe'd executables only have the ziparchive on their
sys.path.

See the 'simple' sample to experiment with this, and to get some ideas.
Also see this entry in the wiki:
<http://starship.python.net/crew/theller/moin.cgi/Py2exeEnvironment>

Thomas





More information about the Python-list mailing list