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

  • Thread starter Satya Nanda Vel Arjunan
  • Start date
S

Satya Nanda Vel Arjunan

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:

import sys
import os
import emc

def main():
aProgramName = os.path.basename( sys.argv[0] )

if __name__ == '__main__':
main()


I would like to exclude the emc module when creating the exe file. To
do this I used the following setup.py:
from distutils.core import setup
import py2exe

setup(
windows=[ { "script": "test.py" } ],
options={ 'py2exe': { 'excludes' : ['emc'] } }
)

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.

satya
 
T

Thomas Heller

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
 

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

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top