Pyinstaller exe not working on other computer(with other windows ver.)

Question:

My platform is Windows 10 and Python 3.9. There is another computer(Windows server 2008R2) without Python. So I’d like to use pyinstaller in my computer and use .exe on the other computer.

I tried simple script print("hello") and used pyinstaller -F myscript.py

.exe works on my computer, but failed on the other computer.

Error
error loading python dll ~ python39.dll

Should I use Python 3.8? Or what should I do?

Asked By: asdfaa

||

Answers:

The problem is that Pyinstaller does not create fully standalone executables, it creates dependencies (E.g. this python39.dll), so this python39.dll should be on the computer which is running this executable. Because python is already installed on your computer, python39.dll is already there and everything works fine. The problem is that machine that you’re running this program on probably won’t have it.

To fix this there are several solutions:

  1. Install python 3.9 on targets’ machine (But in this case you don’t need to create an executable)
  2. Include python39.dll with your program

For second solution just create a folder and move your executable into it as well as this python39.dll library. Windows will find it because it’s in the same directory where this executable is. You can get this library from c:WindowsSystem32 folder (Or where all DLL’s are stored on your system) and then just copy it into folder with your executable. After that ship not just executable but this folder with library included.

@Stepan wrote in comments that you can also include this library right in your executable by adding –add-binary "pathtopython39.dll" to your command when compiling. The final command will look like this:

pyinstaller -F –add-binary "c:WindowsSystem32python39.dll" myscript.py

Answered By: user14203455

Check if the Python version is compatible with the windows version you are trying to use. I was having this problem with an exe I did using Python 3.10. Did it again with Python 3.7 and it worked.

Answered By: Bruno Amaral

In such cases it could be a solution to use something like auto-py-to-exe wrap for pyistaller: it knows better which option to set for py converting 🙂
Also, from my exp, in some cases you should modify yout already normally working from terminal Py code before pyinstaller: for example replace exit() with sys.exit() and so on.

Answered By: Bohdan
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.