Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pyinstaller generated exe doesn't work properly

I'm trying to package a python program/script (pastebin link) I wrote which includes a GUI using the tkinter module. I decided to use Pyinstaller and according to them it supports Python 3.7.

Currently, trying to run pyinstaller seems to generate no issues when actually packaging. It is after when I try to run the executable that it fails. One I generate a one file variant of the executable, it simply opens a command prompt and hangs. When I do the non one file command, it opens and closes immediately, but gives an error output which I can't see due to how quick it closes. I opened up the executable directly in the cmd to get around that, and it gives me this error:

C:\Users\mqian\Desktop\CGIProject\autoprimercode\windowsversion\build\windowsaut
oprimer>windowsautoprimer.exe
Error loading Python DLL 'C:\Users\mqian\Desktop\CGIProject\autoprimercode\windo
wsversion\build\windowsautoprimer\python37.dll'.
LoadLibrary: The specified module could not be found.

I don't know if it's supposed to be looking for the python37.dll in this folder, but nevertheless, I had the bright idea to copy the dll from the python directory into the specified one by the trace (obviously it shouldn't have to be like that). And now the error I get is this:

C:\Users\mqian\Desktop\CGIProject\autoprimercode\windowsversion\build\windowsaut
oprimer>windowsautoprimer.exe
Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\rthooks\pyi_rth__tkinter.py", line 28,
in <module>
FileNotFoundError: Tcl data directory "C:\Users\mqian\Desktop\CGIProject\autopri
mercode\windowsversion\build\windowsautoprimer\tcl" not found.
[6600] Failed to execute script pyi_rth__tkinter

An endless amount of googling hasn't yielded anything concrete. Here are some relevant links that I thought might help.

https://github.com/pyinstaller/pyinstaller/issues/2149

https://www.xoolive.org/2015/09/09/issues-on-loading-dlls-with-pyinstaller.html

PyInstaller: "No module named Tkinter"

https://github.com/pyinstaller/pyinstaller/issues/2495

Error loading python27.dll error for pyinstaller

and here's the specfile I have:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['windowsautoprimer.py'],
             pathex=['C:\\Users\\mqian\\Desktop\\CGIProject\\autoprimercode\\windowsversion'],
             binaries=[],
             datas=[],
             hiddenimports=['tkinter', 'Tkinter'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='windowsautoprimer',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='windowsautoprimer')
like image 681
Thunderpurtz Avatar asked Oct 09 '18 20:10

Thunderpurtz


People also ask

Why is the .exe file created by PyInstaller not working?

The most common reason a PyInstaller package fails is that PyInstaller failed to bundle a required file. Such missing files fall into a few categories: Hidden or missing imports: Sometimes PyInstaller can't detect the import of a package or library, typically because it is imported dynamically.

How do I fix PyInstaller not working?

To Solve 'pyinstaller' is not recognized as an internal or external command operable program or batch file Error You just need to add python script in your path to solve this error.

Do you need Python to run a PyInstaller exe?

They do not need to have Python installed at all. The output of PyInstaller is specific to the active operating system and the active version of Python. This means that to prepare a distribution for: a different OS.


1 Answers

Had the same issue but then realized that I was inadvertently trying to execute the file in the build folder instead of the dist folder.

Looks like you might be making the same mistake from your traceback so see if using the executable in dist doesn't fix it for you

like image 146
Will Ayd Avatar answered Oct 18 '22 05:10

Will Ayd