Search code examples
pythonpy2exe

Can import py2exe at command prompt and in scripts but can't run setup.py at command prompt due to "module not found error."


I'm working to take several scripts I've written and create both Mac applications and Windows executables using py2app and py2exe, respectively. I'm doing the Mac work on my own machine and have encountered no problems. For Windows, I'm forced to access my school's computer via Remote Desktop. There I'm using IDLE with Python 3.8 on Windows 10. All python packages are installed by my system administrator.

py2exe has been installed as the picture below shows:

enter image description here

I'm able to import py2exe at the IDLE shell and import it inside scripts. However, when I try to follow the tutorial at https://www.py2exe.org/index.cgi/Tutorial#Step2 and run the "hello world" example, I encounter a problem. My setup is as shown there:

from distutils.core import setup
import py2exe 
setup(console=['hello.py'])

At the command prompt, I type

python setup.py py2exe

But I receive the "ModuleNotFoundError: No module named 'py2exe' found" error message.


Solution

  • Uninstall python-3.8 and install python-3.4 to get py2exe working. Or use the python-module virtualenv to keep both versions. Here is my answer with code on using virtualenv to get py2exe or pyinstaller working.