简体   繁体   中英

Cannot open .exe after pyinstaller convert

Running my GUI application created in PyQt5 using any IDLE or the file.py is running perfectly, however, when I converted the .py to .exe using Pyinstaller I get an error every time I try to run the .exe file for some reason a small command window pops with an error and immediately disappear I screenshot the error before it closes. Any Idea Thanks in advance

Error image .

I tried to execute different commands for pyinstaller but no luck.

<pyinstaller filename -F > 
<pyinstaller filename -onefile >
<pyinstaller filename >

It's an app over 900 lines and I cannot upload all of that but I think according to the error first lines. The error occurs so here are the lines of code. The problem is within importing modules I believe.

from PyQt5.QtWidgets import QWidget
from PyQt5 import QtCore, QtGui, QtWidgets
from datetime import datetime
import time
import os, sys  #importing system modules

class Ui_MyTrophiesWindow(object):
    class save_txt_file(QWidget): 
     def GetSaveFile(self):
            path = QFileDialog.getSaveFileName(self,"Save MyTrophies.txt here", "MyTrophies", "*.txt")
            working_path = os.path.abspath(__file__)[0:-13]
            file = open(str(working_path) + "Txtpath.dat", "w+")
            for i in path:
                file.write(str(i))
            file.close()

It is very common that sometimes PyInstaller won't recognize all Qt5 dependencies especially QT core DLLs. A simple way is to just locate that file on your current Python path and feed it with add-data flag in PyInstaller. Also, I suggest you not to use upx with PyQt as it may corrupt some DLLs:

pyinstaller --noupx -F --add-data "<Python_path>/Lib/site-packages/PyQt5/Qt/bin/Qt5Core.dll;./PyQt5/Qt/bin" script.py

To verify the answer suppose below example:

import traceback
import os
import sys


def func():
   from PyQt5.QtWidgets import QWidget
   from PyQt5 import QtCore, QtGui, QtWidgets


try:
   if getattr(sys, 'frozen', False):
      print(sys._MEIPASS)
   func()
   print("Import OK!")
except Exception:
   traceback.print_exc()

input()

After you run the executable you would see the path for Pyinstaller (something like C:\\Users\\User\\AppData\\Local\\Temp\\_MEI90202 ), go to this path and search for the Qt5Core.dll and check if it is there.

I had look your error and according to me, I think you need to (re)install Qt5core.dll module and to add it in the site-package/PyQt5/ init .py path. You can download the dll file here:

http://www.telecharger-dll.fr/dll-Qt5Core.dll.html

Good evening

Make sure that you have all the items of that app in the correct folder. Let me put an example that happened to me days ago:

I had an app with a folder named "options" that had 3 files (2 icons for my buttons ui and a .ini file). When I created the pyinstaller version of my program I assumed that it would somehow copy those files and pack them inside the --onefile file or into the dist folder (if not --onefile command was used). Nope, it didn't. After scratching my head for hours, I just copied the options folder from my source files and pasted it next to my --onefile file (or inside the dist folder).

After that, my app works without issues. So... make sure it has all the files it needs in the correct folders.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM