I am fairly new to python, and am having issues using PyQt5. Basically, i am trying to run the code i got from following this website (QtDesigner and PyQt5 basic tutorial), but am having issues:
https://nikolak.com/pyqt-qt-designer-getting-started/
I am using Python 3.6.1 on Windows with PyQt5. I am aware that the above tutorial uses Python 2 and PyQt4. I don't think that is part of the issue, but I could be wrong.
I try to run the main.py script from the above tutorial, and i get this error:
AttributeError: module 'PyQt5.QtGui' has no attribute 'QMainWindow'
because of line 6 in main.py. I assume that this is because PyQt5 is not properly installed, so I use pip:
pip install pyqt5
but get the following error:
Could not find a version that satisfies the requiremenet pyqt5 (from versions: )
No matching distribution found for pyqt5
I realize that some of the above main.py code will only work for pyqt4, I am just trying to get past the issue of not being able to correctly import PyQt5. Another program, that is made for PyQt5 and python 3.6, is having similar issues. When I try:
from PyQt5.QtWidgets import QMainWindow
I get this error back:
ImportError: cannot import name 'QMainWindow'
I have been trying to fix this issue for a while now, and have not found anything that has helped my situation thus far. Any help would be greatly appreciated, so that I can finally get this thing to work.
Like Dan-Dev mentioned in the comments you should try "pip3 install pyqt5". If pip3 isn't being recognized that likely means it hasn't been added to the path. This link will help you find where your python directory is:
How to install pip3 on Windows?. This link will help you add it to the path:
https://www.java.com/en/download/help/path.xml
In PyQt5 the QMainWindow is part of the QtWidgets library, so the first error you are getting is entirely expected.
I'd recommend you take a look at some PyQt5 examples as the differences are minor but they will continue to trip you up while learning how to use PyQt. Take a look at this:
Is there a tutorial specifically for PyQt5?
Related
I have been attempting to learn PyQt5 in order to create GUI.
Pip installed the PyQt5 & the PyQt5.tools yet when I attempt to use it
using Visual Studio Code (while having the Python Extension of VS Code installed) I receive an error.
VS Code detects PyQt5 up to PyQt5.QtWidgets, yet it says no module inside QtWidgets named QApplication can be found.
Import Error of VS Code
On the contrary when it comes to the error, when I attempt to import QApplication from python.exe, no errors nor problems are presented.
Python.exe 'from PyQt5.QtWidgets import QApplication'
This leads me into thinking the problem resides at VS Code's doorstep..
Thanks for your time/answers.
open the cmd from start menu (Command Prompt)
type pip install pyqt5
type pip install pyqt5-stubs
install the integration of PyQt5 from VSCode Marketplace
if is it still not working try uninstalling PyQt5 (pip uninstall pyqt5)
and install it again
Search "PYQT Integration" on ur VS Code Extension shop
Install it
Set the configurations (ur pyqtdesigner path and pyuic etc)
this may help u
I had the same problem with lots of modules specially pytube . PyQt6 , It was all resolved when I changed my interpreter to python 3.11
I have built a GUI using PyQt5 and wanted to distribute it to other computers without Python installed by packageing it with pynsist. Unfortunately, when launching the shortcuts produced by the installer, the GUI does not open as expected and Python keeps crashing (even if Python is instlalled).
The console shows the following error upon crashing:
ModuleNotFoundError: No module named 'sip'.
This is due to from PyQt5.QtCore import *.
Unfortunately, when launching the .launch.py script on a computer with Python installed, everything works fine. I suppose this is because it then targets the installed version instead of the version included in the build of the GUI.
However, the shortcuts do not work, no matter if Python is installed, giving me the above error.
Any ideas how to fix this problem and make the shortcuts work on computers that do not have Python installed?
Thank you in advance!
When I first encountered this problem I simply added sip.pyd to my project-folder. You can find it under:
x:/path-to-python/Lib/site-packages/sip.pyd
but what realy solved my problem was using pyinstaller.
It automatically detects most dependencies and most of the time runs without complicated configurations.
pip install pyinstaller
pyinstaller main.py
# done
Sip is a separate package which PyQt5 requires. You can include it with your application by listing it in pypi_wheels=, as in the PyQt5 example:
[Include]
packages=listapp
pypi_wheels= PyQt5==5.6
sip==4.18
If you're using the latest version of PyQt5 (5.10.1), then the latest version of sip (4.19.8) should work with it.
I'm a complete newbie when it comes to Python programming and I would like to dive myself into Python GUI application programming and have been trying to get Pyforms to work on my Macbook 12" 2017 running macOS High Sierra 10.13.3
I followed the instruction listed on pyforms documentation website right here on how to install it.
I installed python on my mac with this tutorial right here:
For the last 20 hours or so I've been dumbfounded by this error that I kept getting whenever I tried to run the example.py that they provided on this page
The error on the terminal whenever I tried to execute python example.py is:
Reason: Incompatible library version: QtWidgets.so requires version 5.10.0 or later, but QtWidgets provides version 5.7.0
I don't understand why this happens as I've made sure to install PyQt5 using pip install pyqt5 and it installed the latest 5.10.0 version.
I'm a total beginner when it comes to this, I tried to google a bunch of stuff and followed multiple tutorials to no avail. So now I have to turn to the professionals in stackoverflow.
Any help would be much appreciated, thank you!
I use python 3.4
I have downloaded PyQt4 from http://www.riverbankcomputing.com/software/pyqt/download
When i configure PyQt4 by running the following command.
python configure-ng.py
I get the following error:
Querying qmake about your Qt installation...
qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
Error: PyQt4 requires Qt v4.1.0 or later. Use the --qmake flag to specify the
correct version of qmake. If you are sure you are using Qt v4 then try the
configure.py script instead of this one.
Please can anyone help me with this..
I had difficulty getting to run but managed via documentation here: PyQt4 install problems on Ubuntu
On an OSX 10.9, I have Qt5 installed. Later I installed Ipython, sip and PyQt5 all build from source. Now here is the problem: when I try to run ipython qtconsole, I have a bunch of errors related to the files in this directory (and its subfolders)
/Library/Python/2.7/site-packages/IPython/
followed by
ImportError:
Could not load requested Qt binding. Please ensure that
PyQt4 >= 4.7 or PySide >= 1.0.3 is available,
and only one is imported per session.
Currently-imported Qt library: None
PyQt4 installed: False
PySide >= 1.0.3 installed: False
Tried to load: ['pyside', 'pyqt']
I assume the problem is that I have PyQt5 instead of PyQt4. Is this the problem or I have missed some thing else?
Is there anyway that I can have qtconsole with PyQt5? If no, what is the easiest way to do so? (preferably, a method that does not involve having two versions of Qt library on one machine).
For sake of brevity I skipped posting the full error message. Please let me know if I should add them from better understanding of the situation.
The problem might be related to your python path.
I had almost the exact same problem. I had installed PyQt using Homebrew and I was getting the same error message. Finally what solved the problem was adding the following line to my .bash_profile:
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
Since I am a beginner myself, I can't help you any further but I hope this solves the problem.
I know this is really old, but I was recently having trouble setting up PyQt5.
The problem was that PyQt5 would install, but some of the sub modules would not. For instance try
import PyQt5 #works
from PyQt5 import * # might fail
If the second command fails, then you have a problem with the PyQt5 setup, and you need to focus on that.
Specifically, ipython+qt will try to import the following
from PyQt5 import QtCore, QtSvg, QtWidgets, QtGui
If any of these sub-modules are broken/missing the qt console launch will quietly fail.
For me it turned out that the PyQt5 installer was failing to make the QtSvg bindings, which ipython tries to load from PyQt5. When you run the configure.py, use the -w option and you will see all the details of the build, allowing you to pinpoint where the install is failing.
In my case, a little googling and I found out that I was missing the QtSvg lib, which can be pulled in easily from the repos.
Setting environment variable QT_API=pyqt5 solved the same problem for me.
I had the same problem, though with the most recent brew of ipython the ImportError included PyQt5 (along with PyQt4 and PySide). So if it didn't work with PyQt5 before, it does now.
Adding the correct PYTHONPATH to .bash_profile fixed it for me, even in my virtualenv. (I don't have the reputation to up-vote or comment on oxtay's answer, where this would be more appropriate...)