someone-or-other someone-or-other - 1 year ago 304
Python Question

How to include components of psutil in py2exe that py2exe can't find?

I am using py2exe on windows 7 to make an app using psutil. I am using python 2.7. I am making a single file executable. When I try to compile the python python program with psutil, near the end it says:

The following modules appear to be missing
['_psutil_bsd', '_psutil_linux', '_psutil_osx', '_psutil_posix', '_psutil_sunos', '_scproxy', '_sysconfigdata', 'builtins']

However, the program compiles fine. When I run the compiled program, it crashes and generates a log file:

Traceback (most recent call last):
File "", line 27, in
File "zipextimporter.pyc", line 82, in load_module
File "psutil__init__.pyc", line 135, in
File "zipextimporter.pyc", line 82, in load_module
File "psutil_psmswindows.pyc", line 14, in
File "zipextimporter.pyc", line 98, in load_module
ImportError: MemoryLoadLibrary failed loading _psutil_mswindows.pyd

I have tried listing in the options part of the setup:

"includes": ["_psutil_mswindows.pyd"]

as well as just

"includes": ["psutil"]

I have also tried including all the modules py2exe listed as missing. With the exception of including psutil, which didn't do anything, py2exe could not find these files.

There are a surprising number of similar questions on this topic online, but none of them have good answers (if any answers at all) and many of the errors are not quite the problem I have.

Update: strangely enough, I found _psutil_mswindows.pyd in build\bdist.win32\winexe\collect-2.7 of py2exe's build directory. I guess for some reason it isn't getting packaged properly.

Answer Source

All these issues come from py2exe including a bunch of system dlls.

Adding the following list of excludes. (Mainly the last 4). Solves this issue.

dll_excludes=['msvcr71.dll', "IPHLPAPI.DLL", "NSI.dll",  "WINNSI.DLL",  "WTSAPI32.dll"]

You can take a look/cross reference the .dll with those found in your system folder for a list of which ones it is included that should not be present.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download