asdfaa
asdfaa

Reputation: 35

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

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?

Upvotes: 3

Views: 16436

Answers (3)

Bohdan
Bohdan

Reputation: 981

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.

Upvotes: 0

Bruno Amaral
Bruno Amaral

Reputation: 1

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.

Upvotes: 0

user14203455
user14203455

Reputation:

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:\Windows\System32 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 "path\to\python39.dll" to your command when compiling. The final command will look like this:

pyinstaller -F --add-binary "c:\Windows\System32\python39.dll" myscript.py

Upvotes: 10

Related Questions