'Pyinstaller - Error loading Python DLL - FormatMessageW failed

I compiled my .py file running following commands:

pyinstaller myfile.py --onefile.

When i run it on my pc(Windows 10) everything works just fine.

When i try to run it on my `virtual machine(Windows 8).

I get the following error:

Error loading Python DLL 'C:\Users\MyUsername\Appdata\Local\Temp\NUMBERS\python36.dll' LoadLibrary: PyInstaller: FormatMessageW failed.

I already googled the error and i found many solutions but none of them worked..

//UPDATE: If i compile it with my virtual machine, everything runs fine on the virtual machine, main pc and even on my windows server.. strange.. so it must be a problem with my main pc.

Kind Regards



Solution 1:[1]

I had a similar problem trying to run a python-based program (aws cli) and getting the "Error loading Python DLL ... LoadLibrary: The specified module could not be found." on Windows Server 2008 R2.

I solved this issue by installing the Visual C++ Redistributable for Visual Studio 2015 run-time components. https://www.microsoft.com/en-us/download/confirmation.aspx?id=48145

Hope it helps!

Solution 2:[2]

You can use auto-py-to-exe instead:

python -m pip install auto-py-to-exe

And then wait for it to download and then write in then cmd (or terminal):

auto-py-to-exe

A screen will appear:

enter image description here

And just make as I made in the screenshot, then press "convert .py to .exe" and then press "show output folder".

Solution 3:[3]

This also happens when you read the .exe file located in build.

You need to run the exe located in dist folder.

If the error persists even on dist folder .exe , check the exact version of python, download python dll from internet for that exact version, in keep in the folder suggested by the error message (path where this dll is missing).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 José Gil Ramírez
Solution 2 Jack Deeth
Solution 3 Shrashti