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...)
Related
I donwloaded PyQt6 using pip install pyqt6 and it had a bunch of errors so I uninstalled it and reinstalled it with pip install pyqt6 --user and the errors dissappeared. problem is trying to use it in VSCODe or any other ide doesn't work. When i write:
from PyQt6.QtWidgets import QApplication, QMainWindow, QAction, QMenu, QMessageBox VSCode gives me the error Import "PyQt6.QtWidgets" could not be resolved. Could someone walk me through what I may of done wrong please?
Try this in VSCode:
On the lower right of the VSCode window you should see the language
mode and version that VSCode is currently using. Something like "Python" 3.10.7.
If you HOVER over this text (like 3.10.7), VSCODE will display the
actual path used for that version.
If you CLICK on the version, you can change the LANGUAGE MODE and VERSION that is being used by VSCode in the window while editing (and executing) Python code. The language and version reflect the path to the library used.
In my case when I looked, the version had changed to a beta version I'd mistakingly installed earlier (3.11.03b). The version I was using when I installed PyQT6 was 3.10.7.
When I changed the version back to 3.10.7, suddenly everything worked again.
In my case, I had been moving things around in migrating from PyQT5 to PyQT6 and was now using a different file folder for my migrated code. I opened up a new VSCode Window and then my new PyQT6 folder, and I failed to notice that VSCode had chosen what it thought was the 'latest' version of the interpreter.
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 have an issue using the pyQt4 library in Atom. I installed the package using the installation file from sourceforge. I have python 3.6 installed. This is the code I have now:
import sys
from PyQt4 import QtGui
Whenever I try to run this I get the following error:
File ".\test.py", line 4, in <module>
from PyQt4 import QtGui`
ImportError: DLL load failed: The specified module could not be found.
I already googled and found a few ways to fix this but none of the solutions worked for me. Here's what I have done so far:
-Confirmed all .dll files are in the main directory(no \bin directory)
-Confirmed both python and qt4 are 64bit.
-Created a an environment path in windows system pointing to qt4 directory
-Uninstalled and installed qt4 again
-Installed qt5 - got the same error.
-Confirmed python3.dll is present in python directory
Any idea what else might be the problem? Or perhaps I should just change to wxpython?
Thanks.
OK, I got it. I don't know why but I had to uninstall and re-install sip again.
I believe I installed pytq4 before installing sip and that didn't work well.
I uninstalled both pyqt4 and sip and installed sip -> pyqt4 in this order.
Hope this helps someone.
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?