Cannot run 'pyside2-uic' on windows executable built with pyinstaller - pyqt

I am using the PySide2 python bindings for Qt.
Update: I have designed some .Ui files with Qt Designer and loading those during run-time, e.g:
from PySide2 import QtWidgets, QtUiTools
UI_CLASS, _ = QtUiTools.loadUiType("win_main.ui")
class WinMain(QtWidgets.QMainWindow, UI_CLASS):
def __init__(self):
super().__init__()
self.setupUi(self) # This sets up layout and widgets that are defined
Version:
Python 3.9.2 final (amd64)
pyside2-5.15.2
Windows 10 (Build 19042.844)
I have successfully built a Windows executable with pyinstaller 4.2.
PyInstaller-command:
pyinstaller .\src\main.py --name=MyApp --noconfirm --windowed --clean --onedir --log-level=ERROR --hidden-import=PySide2.QtXml --icon=.\img\MyApp.ico --add-data="LICENSE.txt;." --add-data="README.md;." --add-data="changelog.md;." --add-data="data;data" --add-data="img;img" --add-data="ui;ui"
The portable Windows-Executable "MyApp.exe" runs fine. But: if I move the dist folder (I want to make a portable windows-program out of my python program) to any remote PC, the exe exits with an error message on the remote PC.
Cannot run 'pyside2-uic'
...
Check if 'pyside2-uic' is in PATH
I tried almost everything to avoid this and I am running out of ideas.
What is missing on the remote PC?
Hint: I get the same result on my PC, when I rename the following folder for testing reasons:
%LOCALPPDATA%\Programs\Python\Python39\Lib\site-packages\PySide2
But copying this folder to my dist folder and putting it into the PATH environment variable does not solve this.
Any help/suggestion appreciated!

Related

Tkinter video player library works fine as script but has issue when converted into an exe. (Failed to execute script due to unhandled exception)

I wrote a python program that uses the library tkVideoPlayer (and others). The python script runs fine without any errors but when I use pyinstaller to convert it into an exe, the exe doesn't run at all and I get the following error. (see image)
Things I have tried already:
Locating the file and moving it to the folder my exe is in.
Using a star import for the library
Using the --hidden option when creating the exe and specifying av/av.libs
Issue occurred due to me using Anaconda 3 (Sypder). It was using a virtual Environment and pyinstaller failed to locate the library correctly.
Solution: Installed python 3 directly onto windows, then installed pyinstaller and and all the libraries I used. Since that isn't a virtual environment it worked fine and the exe ran perfectly.

Shiboken2 ... ImportError: DLL load failed: The specified procedure could not be found

I've recently been running into a Import Error from Shiboken2 that I didn't have before with my executable. I have an application that I built in PyCharm and I build an .exe for it with CX_Freeze. I have tried every single latest version of Python but I am 100% confident now that it's not the version of Python I have that is the issue. Especially, since the app run's perfectly when I run the source code, but when I use my Setup.py script to build it, I keep getting the following issue when I try to run it:
Here is how my Setup.py script looks:
import sys
import os
from cx_Freeze import setup, Executable
sys.path.append(os.path.abspath("./src/"))
sys.path.append(os.path.abspath("./src/gui/rc/"))
sys.path.append(os.path.abspath("./database/component_actions"))
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = {
"packages": [
# Facile sub-packages
"src.gui",
"src.qt_models",
"src.data",
"src.libs",
"src.tguiil",
"src.graphics",
"src.tools",
],
"includes": ["scipy.sparse.csgraph._validation",
"scipy.ndimage._ni_support",
"scipy._distributor_init",
],
"include_files": ["database/",
"src/tguiil/",
"src/data/"
],
"excludes": ["scipy.spatial.cKDTree",
]
}
installOptions = {"skip_build":True}
base = None
# Uncomment for GUI applications to NOT show cmd window while running.
if sys.platform =='win32':
base = 'Win32GUI'
executables = [
Executable(script = 'src/facile.py', base=base, targetName = 'facile.exe', icon = 'resources/facade_logo_256.ico')
]
setup(name='***',
version = '***',
description = '***',
options = {
"build_exe": buildOptions,
"install_exe": installOptions,
},
executables = executables)
(Sorry there's some info I am trying to remain hidden so that's why I use ***)
When the Problem started:
I updated Shiboken 2 to version 5.15.0 but I was aware that I needed to update Pyside2 so I don't understand how this updated packages effects my executable build.
If need be I can show all my dependencies but I don't think that's the issue because as I said before the source code works properly when I run it on PyCharm, only when I build the executable and try to run it do I have this issue. Maybe this is a PATH issue? Or some dependency I need to include in the setup.py?
B.T.W. I am using a Virtual Environment with Python 3.7.4 32-bit as the interpreter.
I believe this issue stemmed from my environment. I don't really have an adamant answer because I did multitude of things such as the following in this order:
Downloaded PyCharm 2020 and deleted PyCharm 2019.
Deleted all my past Python packages/executables/dependencies, deleted my old virtual environment, and old build folder.
Reinstalled Python 3.7.4 and checked the PATH tab.
Added a Python Interpreter with the Python 3.7.4 in virtual environment through PyCharm 2020's IDE.
Pip installed all necessary dependencies from my requirements.txt.
I made sure to give PyCharm enough time to think (load) in between each step and once I was finished I built the executable and it ran correctly.
I hope this helps anyone who runs into a similar problem.

Can't get .exe to execute on other machine - "No module named serial" error

System: Python 3.7 64x running on Windows 10. I also have Anaconda installed on my machine and I program through VS Code. All modules have been installed, verified installed, and are up-to-date.
I have written a script and compiled it into an .exe using pyinstaller. pyinstaller -wFi pyico.ico endpointapp3.py.The .exe works and runs on my machine but it's not meant for my computer. Previous iterations of this script have been compiled, tested, and worked appropriately on its destination computer, a Windows 7 machine with no python installed.
My latest version now includes pyserial, and works, again, on my machine, but I after compiling and creating an .exe file for the destination machine I encounter this error.
File "endpointapp2.py", line 9 in <module>
ModuleNotFoundError: No module named 'serial'
[3512] Failed to execute script endpointapp2.py
Line 9 is my import serial line
As I mentioned before, this executable runs on my machine, but not on the destination machine it was designed for. I don't want to install python, or python modules on the destination machine because I want the .exe to be all inclusive.
Questions:
Why am I getting this error? What does it mean?
Is there a work around that allows me to compile everything together (using pyinstaller) that will hold all the necessary module
information within the .exe?
Is there something else I should be adding to my original script that will allow me to work through this?
NOT A DUPLICATE - This post is for compiling and running python .exe's on another machine, independent of python, with no modules or python installed.
With some assistance and helpful advice (thanks martineau) I was able to solve my problem. When compiling with pyinstaller, it makes a .spec file that it actually uses to compile to .exe.
Here I found the necessary steps to make sure I was adding the files I needed for pyinstaller.
Here I found out how to properly add the module information into my compiling code.
Once pyinstaller had the correct info in the .spec file I was able to compile and execute on the destination machine as intended.
I solve this issue when i move my code into serial module location.
First find where serial module locate :
>>> import serial
>>> serial.__file__
'C:\\Program Files\\Python310\\lib\\site-packages\\serial\\__init__.py'
mine is above.
Then move your file into :
'C:\\Program Files\\Python310\\lib\\site-packages\\{your_file.py}'
Then run pyinstaller :
pyinstaller --onefile your_file.py --additional-hooks-dir serial\\__init__.py
Run your .exe from dist folder. No longer showing error.
The module is called pyserial, but the library call in the code is import serial. Pyinstaller is unable to complete the build because there truly is no module named serial.
To correct this you need to tell pyinstaller to import the correct package by including it in the .spec file under hiddenimports.
hiddenimports=['pyserial']
This will be true for any case where the package name and the import statement call are not the same.

How do I distribute my Python 3.6 application with all dependencies like in SqueezeTool

I have a python application that I built on Kivy for the GUI, and I separated that file from the RNN model. I just import that file directly with:
from keras_network import Network
I tried using the official trick to deploying using pyinstaller, but that doesn't work, as my application crashes, when running the final .exe file generated. I even made appropriate changes to the .spec file.
Isn't there an easier way to package this application in Python 3.6? (like SqueezeTool, which is too old, and isn't working in Python 3.6)
Can I compile the python files to .pyc files and have all dependencies statically linked? And why is this still such a big pain, when Python is so popular?
Ok... I finally got it to work.
I came up with this solution after I implemented the whole project in PyQt5, and while trying to package it with PyInstaller.
Here is how I got it to work (for people who could have any problems later):
Used python 3.5
Install Windows 10 SDK for some missing files that should've been with MSVC 2015.
Install the dev version PyInstaller from:
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip --upgrade
Used the command to include my data files, as well as including hidden import h5py:
pyinstaller --add-data keras_model.h5;. --add-data TrainingData.txt;. --hidden-import=h5py --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy project-name.py
Then edited the .spec file generated. Added "from kivy.deps import sdl2, glew" without the quotes in the beginning of the file after the comment. Also added "*[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)]," without the quotes in the COLLECT() function call as the 6th argument.
Then used the following command to rebuild using .spec file:
pyinstaller --add-data keras_model.h5;. --add-data TrainingData.txt;. --hidden-import=h5py --hidden-import=h5py.defs --hidden-import=h5py.utils --hidden-import=h5py.h5ac --hidden-import=h5py._proxy project-name.spec
Then the built application's executable was present in the 'dist\project-name\' directory. Double clicking the application lead to the application executing perfectly.
Hope this helps anyone stuck in the same place.

Creating single executable file with cx freeze for .py files

I have created a python program and want to compile it to .exe file in python 3.6.
As pynput is not yet supported for python 3.6, I used cx freeze.
It compiles the program without any error but the problem I'm getting is, I want to compile my .py program into only one single .exe file, but cx freeze creates a build folder with lots of folders in it. Without those folders, the exe file is not running.
How to solve this?
According to the documentation
cx_Freeze does not support building a single file exe, where all of
the libraries for your application are embedded in one executable
file.
So, I'll advice you to use pyinstaller.
pip install pyinstaller
pyinstaller -y -F pythonfile.py
Or if you prefer gui try auto-py-to-exe
pip install auto-py-to-exe

Resources