Search code examples
pythonpy2exe

ImportError: MemoryLoadLibrary failed loading win32crypt.pyd: The specified module could not be found. (126)


After creating an exe of a script (the script was working on its own) with py2exe I got the following error:

Traceback (most recent call last):
  File "script.py", line 3, in <module>
  File "zipextimporter.pyc", line 167, in exec_module
  File "src\import_clixml.pyc", line 1, in <module>
  File "zipextimporter.pyc", line 150, in create_module
ImportError: MemoryLoadLibrary failed loading win32crypt.pyd: The specified module could not be found. (126)

Which was weird, because I compiled a different script using the exact same library and there it worked just fine. It didn't even work when bundle_files = 3 option was used and the file was clearly available in the location the exe was searching in. It also used to work fine with Python 3.10 and old way of creating exes (distutils and python setup.py)

MCVE:

Python 3.11

py2exe 0.13

script.py

import win32crypt

setup.py

import py2exe

py2exe.freeze(
    windows=[
        {
            "script": "script.py",
        }
    ],
)

Running the setup.py creates an exe, but trying to run it results in an immediate error with import win32crypt not found error.


Solution

  • For some unexplicable reason, adding import pandas to the script makes the created exe work correctly, even though the modules should have no effect on each other.