PyQt5 not found in PyCharm - python

I would like to use PyQt5 on my PyCharm but If I try to import it I get
ImportError: No module named PyQt5.
I looked for hours other answers but the issue doesn't seem to be fixed. I'm running MacOS X 10.13, PyCharm 2019.3. What puzzles me is that if on PyCharm I go to
Preferences > Project interpreter
then PyQt5 shows up among the packages that I have installed. Could anybody help?

Related

PyQt5 gets "No module named 'PyQt4'" error calling matplotlib.pyplot in Python 3.5

I am using Anaconda with Python 3.5.2, Matplotlib 2.0.2, PyQt5.6 on a windows 10 machine. When I import matplotlib.pyplot as plt I get the following error:
...
File "C:...\Anaconda3\Lib\site-packages\matplotlib\backends\qt_compat.py",
line 137, in <module> from PyQt4 import QtCore, QtGui
ImportError: No module named 'PyQt4'
I don't know why it would want to import from PyQt4 when it has never been installed on my machine.
This question has the same error, but on a machine that actually has PyQt4 installed.
I have checked my matplotlibrc file, I've used matplotlib.use('qt5agg') in the program, also matplotlib.rcParams['backend'] = "Qt5Agg". I've uninstalled and reinstalled all the above packages to no avail. I have even attempted to install PyQt4 just to get things going. I'm completely stumped. None of the various possible causes or remedies that I've been able to find on either SO or github have helped.
I just had the same error (even though on Windows 7). For me the problem was that there was an old matplotlibrc file in C:\Users\<username>\.matplotlib\matplotlibrc which overwrote the settings from my environment's matplotlibrc file. Deleting that file solved the issue for me.
It seems the API version is PyQt5 but the default is PyQt4,just open Tools -> Preferences -> IPython console -> Graphics -> backend,change QT4 to QT5
Looking at the file and line number in your error it looks that you have the same issue that I answered here.
That is, I think your issue is caused by having a QT_API environment variable that still is set to pyqt4 (or pyside).
I ran into a similar thing and found that the problem was having a 64-bit Anaconda installation that couldn't load the PyPt5 DLLs that were perhaps 32-bit. The short answer is that I uninstalled Anaconda 64-bit and installed the 32-bit version instead.
To work through this, I stepped through qt_compat.py where the error originates. For most of the time through this module, it’s trying to work with PyQt5, as that’s what it finds in the environment. However, when it gets to the lines below, the import fails so it tries to fall back to PyQt4, which isn’t installed with Anaconda, and thus issues the error.
if QT_API == QT_API_PYQT5:
try:
from PyQt5 import QtCore, QtGui, QtWidgets
_getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
except ImportError:
# fell through, tried PyQt5, failed fall back to PyQt4
QT_API = rcParams['backend.qt4']
QT_RC_MAJOR_VERSION = 4
Testing the import statement outside of the file gave the message “DLL load failed: %1 is not a valid Win32 application.” That's what suggests the DLL mismatch, and also answers why it was trying to fall back to PyQt4.
3 steps can solve this problem:
pip uninstall pyqt5
pip uninstall matplotlib
pip install matplotlib
I had faced the same problem and here is how I fixed it.
Look into your matplotlib configuration file which is often located at
path-to/site-packages/matplotlib/mpl-data/matplotlibrc
or
path-to/Anaconda3/envs/your_env_name/Lib/site-packages/matplotlib/mpl-data/matplotlibrc
See an example of matplotlibrc here
https://github.com/daler/matplotlibrc/blob/master/rc/default
If you have pyqt5.x.x installed and have the statement 'backend : Qt5Agg' in matplotlibrc, then to use '%matplotlib qt', change '#backend.qt4 : PyQt4' to '#backend.qt4 : PyQt5'.
For an Anaconda environment, reactivate the environment.
Note if you update matplotlib in the future, your matplotlibrc will automatically be overwritten.

install and use pygame on Mac Yosemite

I installed Pygame on my mac using Anaconda.
pip install pygame
>>>Requirement already satisfied: pygame in /anaconda/lib/python3.6/site-packages
The thing is, I do not know to use it now. When I run a simple file from my code editor it says:
File "/Users/julien/untitled5.py", line 1, in <module>
import pygame
ImportError: No module named pygame
any advice ? I tried to run pygame using spyder from the Ananconda Navigator bun it does not seem to work either.
The issue is that your IDE is looking in the wrong places for pygame. To see where it's looking for packages, run this script in the console for that IDE:
>>>import sys
>>>sys.path
This will show a list of paths where python looks for packages. /anaconda/lib/python3.6/site-packages won't be there, which is why you can't import it. What IDE are you using? Most are able to change their settings so that they can import from different places, see if you can do that, and put /anaconda/lib/python3.6/site-packages as part of the path.

QT Webengine for Ubuntu

I have several different qt packages installed for my development environment on Ubuntu 15.04 (3.19.0-51-generic), and I can't seem to get my imports correct. The error I am running into in PyCharm is:
from PyQt5.QtWebEngineWidgets import QWebEnginePage
ImportError: No module named 'PyQt5.QtWebEngineWidgets'
The following packages I have installed already, which I believe to be relevant are as follows:
python3-pyqt5
python3-pyqt5-dbg
python-pyqt5
python-pyqt5-dbg
pyqt5-dev-tools
pyqt5-dev
python-pyqt5.qtwebkit
python3-pyqt5.qtwebkit
python-pyqt5.qtwebkit-dbg
python3-pyqt5.qtwebkit-dbg
What am I missing here? Note that the project explicitly requires the following in its README:
Qt 5.5+
PyQt5.6+
Furthermore, I understand that webengine and webkit are two different things (I was giving it a stab). I can't find any Webengine for PyQT5 anywhere in the official Vivid repository. I tried installing libqt5webengine5-dev and libqt5webengine5 from https://launchpad.net/~ethereum/+archive/ubuntu/ethereum-qt packages with the same result, perhaps I need to add something to Python path. Can anyone lend a hand (Im normally a .NET developer :/)?

PyCharm and PyQt5 unresolved reference but working

I have installed PyQt5 using the windows installer. I have tried creating some windows and stuff and it works great. Still, pycharm seems to not like PyQt5 very much, and is marking errors everywhere in my code.
As I said, PyQt5 is working great, but it's kind of annoying to have those errors which, by the way, i can not alt + enter + ignore them.
I guess it's just a matter of adding references or something to pycharm, but I have no idea how to do it and I have already spent 1 hour trying to look for solutions in stack-overflow, and none of them work. I have also tried re-installing it.
I am using windows 7 64 bits, python 3.4, and PyQt5 of 32bits because 64 didn't work for some reason.
I had similar problem because I had both PyQt4 and PyQt5 installed.
In general this can cause all sorts of problem, so the spyder-ide guys made the qtpy package, which gives an abstraction on top of the PyQt5/PyQt4/PySide.
Nowdays the qtpy is a standard library in the Anaconda distribution, and you can call it instead of PyQt5/PySide likes this:
from qtpy.QtCore import QFile, QFileInfo
from qtpy.QtGui import QIcon, QKeySequence, QPixmap
It solved me this specific problem in PyCharm.
I also have both 32 bit and 64 bit Python v3.5 and PyQt5 versions installed. That should not matter because I installed the 32 bit PyQt5 package in the 32 bit PI and the 64 bit PyQt5 package in the 64 bit PI. I installed the PyQt5 packages from Riverbanks's PyQt5 web site. Christopher Gohlke does not have them yet on his Windows extensions site, nor does PyCharm's PI dialog even list PyQt5 as an available package.
PyCharm does indeed incorrectly flag numerous warnings whether I choose the 32 bit PI or the 64 bit PI for the PyQt5 project I am working on. This appears to be a cosmetic bug only for PyQt5 code, since the code does run correctly, even if I run the code from PyCharm's Terminal window. Also, note that PyQt5 is not listed in PyCharm's PI settings dialog, even though Windows 10 File Explorer does indeed list the proper packages in the proper site-packages folder. Doing a PyCharm Invalidate/Restart does not help.
That said, you do not have to, nor should you, suppress warnings for everything. Just suppress warnings on a case by case basis only for PyCharm's incorrect PyQt5 warnings. You can do it like this:
def __init__(self):
# noinspection PyArgumentList
super().__init__()
In my case I needed in my PyCharm to go File -> Settings -> Project: MyProject -> Project structure and chose correct Project Interpreter
Another probable and easy means is to:
open the command prompt as an administrator
type in 'pip' (without the quotes)
type in: pip show PyQt5 (this shows you where PyQt5 has been installed.
follow the trace given to you from the command prompt. Now, open the folder 'site-packages' and copy every folder termed' PyQt5' to the 'lib' folder instead (ignoring those with '.. - info' is inconsequential).
In Pycharm or Visual studios, the red underline goes off and the problem of 'unresolved reference' is eliminated.

PyQT5 Python 3.3 Pycharm

I am new to python and I have an issue running PyQT5 for my Python 3.3 on PyCharm.
I have read several posts about it, some speaking about doing a build which I am not sure to get.
Here is what I have done :
Downloaded and run the .exe found here.
Installing normally, the same way as my Pillow for instance (which is running with my Pycharm).
aaaand, that's its.
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
== from PyQt5.QtCore import *
ImportError: No module named 'PyQt5.QtCore'
When I setup the module in PyCharm it simply didn't find it. So is the .exe found on the official PyQT5 dead ?
Thanks
Bloby
I also met the same problem recently, maybe you also install PyQt5 by pip?
It seems that the after using pip, I can import the PyQt5 but not any packages of it, so I have to download the old version with an installer.
Then Pycharm can runs without error.

Categories

Resources