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.
Related
i create an app in Python with Tkinter. When I execute this code with Pycharm it works, but after creating the exe i get this error. I load the error screen
I used pyinstaller to create the exe: pyinstaller.exe --onefile --windowed --icon=icona_interfaccia.ico v2_tkinter_robot_gui.py
The app code is divided into four folders, called:
Vision_Code
Interface_Code
Manual_movements_Code (Codice_Manuale)
Kinematics_Code (Codice_Cinematica)
All this four folder are saved in one call Code.
The v2_tkinter_robot_gui.py is the main file, where all the codes I wrote converge and it is saved in the folder called Interface_Code.
To import my modules I use the following wording:
from Codice_Manuale.Movimentazione_manuale import moveJabs, moveJ
#from Codice_Cinematica.cinematica_pallettizzatore import *
#from Codice_Manuale.funzioni_gestione_meccanica import aggiusta_zeri, workspace,
finecorsa_angoli, home_braccio
from Codice_Visione.movimento_ciclo_completo_visione import *
from Codice_Visione.movimento_immediato_visione import *
I had already created an exe on another machine that I no longer have. On this one it worked without problems.
Thanks in advance for the help
[Thanks to Charles Duffy for the gentle nudging toward a clearer question! I am new to Stack Overflow and appreciate the help. After more research, it appears that the dependent code is actually within Blackmagic's fusionscript.dll code (If the .dll is missing, my exe is able to continue past the line of my code which tries to import) , so I don't see any way to get around it until they update.]
Original question:
I'm stuck trying to get a pyinstaller executable to work on a Windows 10 test system. My exe works fine on a system that has Python 3.6.8 installed.
Complete code is below. The print command that starts with "trying:" succeeds and shows the correct path for the import. The print command immediately after the import command print("Made it past import") is not executed, and the exe quits without showing any errors.
I've determined that there's just one file that is necessary for the exe to run on the test system, and that's the os.py file in the Lib folder of the Python install. Without that file, the exe just quits (without any error message) when it hits the line of code: script_module = imp.load_dynamic("fusionscript", path + "fusionscript" + ext)
For anyone trying to reproduce: the exe runs when a Python 3.6.8 install is present, or more specifically, when os.py is. I made the installer with a simple pyinstaller importTest.py command. I place the fusionscipt.dll in the folder with the resulting executable. If os.py is present, the exe runs normally and prints all of it's print commands. If you remove os.py from the Python Lib directory, this is no longer the case, and the exe quits when it hits the imp command.
NOTE: I know that imp is deprecated, but the API that my code engages with (fusionscript.dll for Resolve) only works with Python 3.6, so I can't use anything newer.
Here's the code:
from PyQt5.QtCore import QObject
import sys
import imp
import os
CURR_DIR = os.getcwd()
sys.path.append(CURR_DIR)
script_module = None
ext = ".dll"
path = CURR_DIR+"\\"
try:
print("trying: " + path + "fusionscript" + ext)
script_module = imp.load_dynamic("fusionscript", path + "fusionscript" + ext)
print("Made it past import")
except ImportError:
pass
print("script module = ",script_module)
I'm trying to open Adv5KTCP.exe (path shown in code) but this exe actually opens three more avi.files as shown in image below. This causes the error. I've tried os, subprocess & pywinauto to call but to no avail. I've also tried adding the files path to environmental variable but I think that makes no sense. Opening the exe from command prompt does not work too. However, the exe can be opened manually by double clicking the exe file (like the usual). I just need it to be automated.
AVI Files:
The Error:
Double clicking the exe would open this window:
Here is my code:
import os
import sys, logging
import subprocess
import ctypes
from pywinauto import Application
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
if is_admin():
exe = "Adv5KTCP.exe" #path set in environment variable: "C:\Program Files (x86)\Advantech\ADAM-5000TCP-6000 Utility\Program"
os.startfile(exe)
# subprocess.Popen([exe])
# application = Application(backend="uia").start(exe)
else:
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
Does anybody have any idea on how I could go about this? Thank you in advance for your response.
New Findings:
I tried to cut the three AVI files to desktop & set desktop path to system variable & the exe gives the same error. However when i cut the exe file to desktop with the avi files as shown below, it works! Even when the other required files are not in desktop but path's set to system variable. Which means the exe is somehow registering the paths of the avi upon click, location/position or some sort which I'm not sure of.
I am trying to build a very basic executable (Windows) using PySide. The following script runs properly in the interpreter (Python 2.7, PySide 1.1.2)
#!/usr/bin/python
import sys
sys.stdout = open("my_stdout.log", "w")
sys.stderr = open("my_stderr.log", "w")
import PySide.QtGui
from PySide.QtGui import QApplication
from PySide.QtGui import QMessageBox
# Create the application object
app = QApplication(sys.argv)
# Create a simple dialog box
msgBox = QMessageBox()
msgBox.setText("Hello World - using PySide version " + PySide.__version__)
msgBox.exec_()
I tried 3 methods (py2exe, pyinstaller and cx_freeze) and all the 3 generated executables fail to execute. The two stdout/stderr files appear, so I found the first PySide import is making everything fail. (Unhandled exception/Access violation)
I analyzed the executable file with depends (http://www.dependencywalker.com/) and everything looks correctly linked.
Any idea?
You need to add the atexit module as an include. source: http://qt-project.org/wiki/Packaging_PySide_applications_on_Windows
(is also the case for Linux btw)
Thank you for your help. Actually, this did not change anything :/ However, I found a solution to my problem: if I add from PySide import QtCore, QtGui, then the executable (with pyinstaller) does work!
I'm trying to compile my first .ui file using PyQt4 on a mac with osx 10.6. I'm getting a syntax error and I'm not sure what it means.
>>> import sys
>>> sys.path.append('/Users/womble/Dropbox/scratch/')
>>> from PyQt4 import QtCore, QtGui
>>> pyuic4 Urb.ui > Urb.py
File "<stdin>", line 1
pyuic4 Urb.ui > Urb.py
^
SyntaxError: invalid syntax
I tried adding
#!/usr/bin/python2.5
as my first line to the .ui file and I still get the same problem.
Thanks for any suggestions.
You're mixing Python and shell commands.
This is Python code and can be executed from an interactive Python session:
import sys
sys.path.append('/Users/womble/Dropbox/scratch/')
from PyQt4 import QtCore, QtGui
This is supposed to be run from a command prompt or terminal window. It's giving syntax errors in your Python interpreter because it's not Python:
pyuic4 Urb.ui > Urb.py
I normally use pyuic4 from the command line in the following way:
pyuic4 -xo Urb.py Urb.ui
The x flag makes sure the generated Python code includes a small amount of additional code that creates and displays the GUI when it is executes as a standalone application.
The o flag specifies the output file to write to (in the example above: Urb.py)
After spending almost 6 hours on finding the right solution, the steps on this page is by far the most accurate that worked perfectly on my mac 10.6.8
http://www.pythonsummerschool.net/index.php?url=mac_pyqt
I can now convert *.ui files to *.py files seamlessly on terminal:
Once you have pyQt configured with sip and all relevant dependencies as described on this link, you have to go to /Applications/Python 3.2/Update Shell Profile.command and run it.
Check your path variables:
env | grep PATH
Once everything is pointing to your latest Python install then you can double check by running /Applications/Python 3.2/Update Shell Profile.command
Then its as easy as
pyuic4 /Volumes/BOOTCAMP/yourfile.ui > /Volumes/BOOTCAMP/yourfile.py
Have fun!