I've packaged a python application written in Python 3.6 with PyQt5 using PyInstaller for MacOS. The application runs correctly, but the interface does not use a native-looking style. Running the program manually does use the correct style, and PyQt.QtWidgets.StyleFactory.keys() gives 'macintosh', 'Windows', and 'Fusion'. When running the packaged application, only 'Windows' and 'Fusion' are available. How can I package the 'macintosh' style with my application and instruct PyQt5 to use the native style?
The error seems to have been fixed in a unmerged branch of PyInstaller. More information can be found on the GitHub pull request conversation, but reinstalling PyInstaller using pip install https://github.com/bjones1/pyinstaller/archive/pyqt5_fix.zip fixed the style issue for me.
Related
I've been looking for a GUI system for python applications for a while and have found these 2, Tkinter and PyQT. The issue I'm having is that I cannot work out whether PyQT requires the end user to have QT installed and whether Tkinter will work properly on another computer as I have read a lot about it being touchy when it comes to Tk/Tcl version.
What I'm trying to do with it is create an application for a friend so that he can keep track of his beehives more easily and I didn't think that having it in a terminal would be the way to go. Thanks.
I have worked with both in the past and from my observations:
whether PyQT requires the end user to have QT installed
Yes, it does. However you can bundle your app along with the dependencies (Python + QT) using tools like PyInstaller. You will get a single package that you can distribute to your users. They can run it without installing anything.
You can also create custom installers which install Python and QT on the target systems for you. Then the users can just run the Python script.
whether Tkinter will properly on another computer as I have read a lot
about it being touchy when it comes to Tk/Tcl version
I have never faced any issues with it since I mostly deployed my Tkinter apps to Windows and I installed the same version of Python on the target systems that I used to develop. However, there might be version conflicts on other platforms (eg. Linux/OS X).
What I'm tying to do with it is create an application for a friend so
that he can keep track of his beehives more easily
Have you thought about web based GUI? A python script running a webserver on a local machine? You can use the "webbrowser" module to open up a browser to load the url when the script is run.
There is another alternative: Kivy.
I've written a Python3 application which uses PyQt5 for the GUI, it runs fine on every desktop system.
Now I would like to run this on an embedded linux (specifically: Yocto BSP) which is delivered by the hardware manufacturer. Since there's no PyQt5 but a qt5 and python3 package running on the BSP, I would like to (somehow) make a standalone executable of the application. Plus I'm not experienced with writing bitbake recipes and creating a custom BSP and have not found any existing PyQt5 recipes.
What I've tried so far (and did not succeed):
Make a standalone executable with nuitka, cx-freeze, pyinstaller (compiled on a similiar arm platform)
Use pyqtdeploy to convert python into c++ source code, then compile it by using the supplied build-environment. I did a static compile of the pyqt5 and sip packages and everything compiles just fine, but make reports undefined references (linker errors) which I cannot resolve (as I'm not very familiar with c++).
Now what's the best approach to let a python/pyqt5 application run on an embedded linux system with very limited packages?
You can see the link
python-pyqt5
First you should get the meta of qt5:
https://github.com/meta-qt5/meta-qt5
Then modify the local.con and you-image.bb to make the qt5 can be compiled into the image.
My setting: Python 2.7 with anaconda
Recently I have installed OpenCV 3.0 and when I try to do simple image display or I want to run python samples that come with OpenCV, there is a error message:
This application failed to start because it could not find or load the Qt platform plugin "xcb".
I have read many comments that I need to attach .so files to my project but I don't think it's the optimal solution since for most people it works out of a box.
I have no clue what to do. I'm inexperienced. What comes to my mind is only to reinstall everything.
Qt5 works fine with OpenCV 3.1.0. This is what worked for me for resolving the "xcb" error.
Apparently the Anaconda qt and pyqt packages (v4) were shadowing the system v5 version.
If you want to work with Qt5 try removing these via:
conda remove qt
conda remove pyqt
(Ubuntu 16.04, OpenCV 3.1.0, Anaconda 4.1.1, Qt 5)
Okey, I have figured it out.
During cmake I set flag -D WITH_QT=OFF since I read somewhere that it doesnt work for Qt5.x
I've got:
Python 2.7 (Anaconda x64), which works great
PyQt5 (installed using pip install python-qt5)
PyCharm 4.04 Professional (recently upgraded from 3.4.1)
A small Qt application
After much hair-pulling (since Riverbank doesn't provide a PyQt5 binary for Python 2.7, only for 3.3+) I got everything working thanks to Marcus Otosson's pre-compiled binary packages.
Qt is now installed and fully functional. My Qt application runs great!
But the application isn't finished yet, and PyCharm won't do code completion for the PyQt modules. It won't even recognize that any PyQt5 sub-modules (like Qwidgets) exist: even though they work just fine, I still get the red squiggly "Unresolved Reference" warning.
How do I fix this? I assume this has to do with the inherent difficulties in generating skeletons for binary *.pyd files. How does it work exactly? Can I manually generate code skeletons, or import them from somewhere they generated correctly?
Uninstalling and re-installing PyCharm didn't help. Neither did re-configuring the interpreter to force the skeleton generator to run again.
Please help before I go bald.
Can you find PyQt5 from your project's External Libraries?
If you install it through pip, you should be able to see the library directly. Once the library can be referred, it will do the code-completion for you.
I am using PyCharm4(community Edititon) on Windows with PyQt4, the autocomplete is fine. As PyQt4 is actually a dynamic library to be dynamic loaded by the python interpreter ( you can look into the PyQt4 folder, there is no python files there except some init.py), auto-complete depends on the source code of PyQt4 itself, so when using pycharm, it usually generally some local python cache for complete. For my machine, a typically file looks like:
C:\Users\cui.PyCharm40\system\python_stubs-762174762\PyQt4\QtCore\QString.py
You can also try install PyQt document from Pycharm.
File->settings->Tools->python external document->PyQt
Had the same problem in PyCharm 2017.1.1. Don't do
import PyQt5.QtWidgets
do
from PyQt5 import QtWidgets
My question is about the easiness of distributing the GUI app across the platforms (Mac/Linux/Windows), and I want to know the one that makes the user's job easiest.
My current understanding is that Tkinter app is the easiest for the users (to install) because as long as the user has installed a Python in her box, my application should be ready to run on that box.
For GUI app written in wxPython or pyQT, the user needs to install wxWidget or QT in her box first, which is an extra step, and then install my GUI app. (But my Ubuntu box seems to have the wxWidget libraries and QT libraries installed by default, is that a norm or just Ubuntu distro is more friendly to users? I guess Windows and Mac probably does not provide them by defualt, ie. the users need to download and install them as an extra step)
If you're running Ubuntu, PyQt will be installed by default. Most linux distros will have one of PyGtk or PyQt installed by default. WxPython was most likely installed in your Ubuntu box as a dependency for some other package in your system.
If your target market is Linux, you can just create a deb or rpm package and that'll take care of the dependencies for your application.
For Windows and Mac(and even Linux if you're so inclined) you could bundle the python interpreter with your application and its libraries into a native executable format such
as .exe, .dmg or .elf using libraries like cx_freeze, py2exe and py2app. Once this is done, your user will not have to install python or any of your libraries.
Tkinter is the only one that's included with Python. wxPython and pyQT need both the wxWindows or QT libraries and the wxPython or pyQT libraries to be installed on the system.
However, Tk does not look very nice. If you're already making the user install Python, you could just as well have them install the libraries too. (Or maybe include an installer or something.)
If the app is going to be cross-platform I would suggest WxWidgets (wxpython). I have used it several times and it has never been a problem.
Nevertheless, you should create different installers for Windows, Mac and Linux. In Linux, use .deb or .rpm to take care of dependencies.
In Windows, I've always used py2exe to create an exe file. Py2exe works by attaching the python interpreter and the needed libraries, in this case wxWidgets.
Check this link for more information: http://www.py2exe.org/