Search code examples
pythoncmdcx-freeze

Windows .exe created with cx_Freeze returns 0xc000007b error


I created a small script to test cx_Freeze, shown below:

sqrt.py:

import math
sqrt = math.sqrt
x = float(input('Enter a number:'))
y = sqrt(x)
print(y)
input('Press ENTER to exit')

I also created a setup script:

setup.py:

from cx_Freeze import setup, Executable

setup(  name = "sqrt",
        version = "0.1",
        description = "Testing",
        # options = {"build_exe": build_exe_options},
        executables = [Executable("sqrt.py")])

Next, I launch Windows cmd.exe in the folder where python.exe, sqrt.py and setup.py are located and enter:

path\python.exe setup.py build

As it should, this creates a build directory, which contains amongst others a sqrt.exe. When I attempt to execute this, it returns

"The application was unable to start correctly (0xc000007b). Click OK to close the application."

For as far as I understand the cx_Freeze documentation, this should work. Ditto for various YouTube tutorials I've watched.

I'm running Windows10 64x, Python 3.5 and cx_freeze 5.0.


Solution

  • You can load the exe file created with cx_freeze with dependencywalker.

    It will show you what's wrong.

    Maybe you are missing a library like Microsoft Visual C++ Redistributable Package or you mix 32 and 64 bit architecture.

    The tool will show what's wrong.

    Update: I had this issue while I tried to get gtk running on windows. There were any strange things. I switched from gtk to pyside2 (QT) and things are much easier now.