Thunderpurtz
Thunderpurtz

Reputation: 199

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')

Upvotes: 6

Views: 8061

Answers (2)

user5422717
user5422717

Reputation: 75

Please recreate the exe with --onefile option in command. It wont ask you for python37.dll

Upvotes: 0

Will Ayd
Will Ayd

Reputation: 7164

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

Upvotes: 10

Related Questions