VCRUNTIME140.DLL is not getting added when using cx_freeze in Python

1

I am very new to Python. I just wrote a program to check the last time the servers were rebooted and send an email to our team. We have over 30 servers and its not possible to install python on every one of them. So I used cx_freeze to create an executable file. Below is my setup.py file.

from cx_Freeze import setup, Executable

setup(
    name = "RebootChecker",
    version = "1.0",
    description = "A Script to check the last reboot time of servers",
    options = {
        "build_exe": {              
            "include_msvcr": True,
            "add_to_path": True,
        }
    },
    executables = [Executable("RebootTester.py", base = "Win32GUI")]
)

The exe file runs file on my computer but when I try it on a server it does not work. It crashes with the error - "The program cannot start because VCRUNTIME.DLL is missing from your computer", even though the DLL is available in C:\Windows\System32. I found that the DLL was missing in the build folder of the python executable. So I manually copied the DLL to the folder in which the exe is present but I got the error - The application was unable to start correctly (0xc000007b). Click OK to close the application

I also tried to add the DLL file by modifying the build_exe by adding the below lines to the setup.py file but got the same error as above.

python_dir = os.path.dirname(sys.executable)
"include_files": [os.path.join(python_dir, "vcruntime140.dll")]

I even tried repairing the "Microsoft C++ Redistributable" application but to no avail.

I saw on a github post that this was a known issue on cx_freeze version 5.0.2, where the Visual studio packages are not added even after adding "include_msvcr": True, but I use version 6.1.

The other answers on SO only give the above methods as solutions and they don't work for me.

How do I get this to work? I have been on this for hours now. Any help on this is appreciated.

Thanks!

python
cx-freeze
asked on Stack Overflow Mar 9, 2020 by Arun

1 Answer

2

It seems your real problem is that 32-bit Python is running on that machine under 64-bit Windows. I guess the Microsoft C++ Redistributable that you installed was 64-bit as well.

  • The vcruntime140.dll file cannot be found because its 32-bit version (which should be under C:\Windows\SysWOW64) probably doesn't exist.
  • When copying the file manually from C:\Windows\System32 (which would then be the 64-bit version!) it fails with 0xc000007b which is the code for STATUS_INVALID_IMAGE_FORMAT because now a 32-bit python.exe is trying to load the 64-bit vcruntime140.dll.

I'd suggest using 64-bit Python on the 64-bit machine instead.

answered on Stack Overflow Mar 9, 2020 by CherryDT

User contributions licensed under CC BY-SA 3.0