1

I am trying to convert a py file to an exe. Here is the code for my setupfile

from distutils.core import setup
import py2exe
setup(console=["mycode.py"])

When I use cmd, it says: Import Error: No module named easygui

How do I let py2exe know about the easygui? As well as the numpy and mathplotlib (all are used in mycode.py)

jdi
  • 90,542
  • 19
  • 167
  • 203

2 Answers2

1

First, use pyinstaller. It is newer and better (though I have used py2exe until switching to pyinstaller) And it seems to have much better recipes for finding your included libs.

But for py2exe, you will need to expand that setup.py a bit more to tell it what to include (since they are probably hidden imports)

setup(
    console=["mycode.py"],
    options={
        "py2exe": {
            "includes": ["easygui"],
            "bundle_files": 1
        },
    },
    zipfile = None,
)

If this fails to build, then easygui is not in your PYTHONPATH properly. Make sure you are not doing something special in your script to add a pythonpath, which would not be visible to py2exe.

You may need to do a little more work with this file for numpy and matplotlib. See this wiki for help

jdi
  • 90,542
  • 19
  • 167
  • 203
  • Thank you this helped, I have a new error now, it now creates the dist file and actually seems to be recognizing the easygui and matplot lib,however when finding dlls this comes: ***finding dlls needed*** error:ligbk-win32-2.0-0.dll: No such file or directory – Waqar Khawaja Nov 24 '12 at 02:02
  • I downloaded that dll and now when i use cmd again it says I now need libgobject-2.0-0.dll – Waqar Khawaja Nov 24 '12 at 02:14
  • Depending on the lib you may have a number of dlls to add. Is this for numpy or matplot? Did you follow the wiki for those modules? – jdi Nov 24 '12 at 02:25
  • yea i downloaded numpy and mathplotlib from there, I can just keep downloading the dll files separately? – Waqar Khawaja Nov 24 '12 at 02:30
  • Well any dll files that you need should be on your system already from installing the packages. The problem is that py2exe needs to know where they are. I don't have much windows experience packaging numpy or matplotlib, but I highly recommend you try pyinstaller. It should at least try a bit harder to get it working out of the box. – jdi Nov 24 '12 at 02:42
  • Okay I made the exe file! now when i run the program, it says"Run time error cannot find the mathplotlib files – Waqar Khawaja Nov 24 '12 at 02:53
  • Btw when i created the exe, here was the message==================== – Waqar Khawaja Nov 24 '12 at 02:56
  • *** binary dependencies *** Your executable(s) also depend on these dlls which you may or may not need to distribute them. Make sure you have the license if you distribute an make sure you don't distribute files belonging to t OLEAUT32.dll - C:\Windows\system32\OLEAUT32.dll USER32.dll - C:\Windows\system32\USER32.dll IMM32.dll - C:\Windows\system32\IMM32.dll SHELL32.dll - C:\Windows\system32\SHELL32.dll ole32.dll - C:\Windows\system32\ole32.dll MSVCP90.dll - C:\Python27\DLLs\MSVCP90.dll KERNEL32.dll - C:\Windows\system32\KERNEL32.dll – Waqar Khawaja Nov 24 '12 at 02:57
0

Relative to the issue of the specific dll's mentioned, I had similar issues but fixed those problems by specifically excluding those in the setup lie so:

setup(
    console=['DET14.py'],
    options={
             'py2exe': {
                        'packages' : ['matplotlib', 'pytz'],
                        'dll_excludes':['MSVCP90.DLL',
                                        'libgdk-win32-2.0-0.dll',
                                        'libgobject-2.0-0.dll',
                                        'libgdk_pixbuf-2.0-0.dll'],
                        'includes':['scipy.sparse.csgraph._validation',
                            'scipy.special._ufuncs_cxx']
                       }
            },
    data_files=matplotlib.get_py2exe_datafiles()
)`

I would say try adding that exclude to your setup statement.

Charlie_M
  • 1,281
  • 2
  • 16
  • 20