PyCharm Error, ModuleNotFoundError: No module named 'PyQt5' - python

I installed python 3.7 and PyQt5 using pip install PyQt5 command. when I import the module in python console of pycharm, it is working alright but when I import it into my project files am getting the following error. I searched through the internet for possible solutions but are not working for me and I also think my problem is different from those that were already asked. any help?
from PyQt5 import QtCore, uic, QtWidgets
from PyQt5.uic import loadUi
from PyQt5.QtWidgets import QApplication,QDialog
import sys
UIClass, QtBaseClass = uic.loadUiType("projj/firstly.ui")
class MyApp(UIClass, QtBaseClass):
def __init__(self):
UIClass.__init__(self)
QtBaseClass.__init__(self)
self.setupUi(self)
self.setWindowTitle('developer in details')
self.pushButton.clicked.connect(self.on_pushButton_clicked)
self.pushButton_2.clicked.connect(self.on_pushButton_clicked_2)
self.pushButton_6.clicked.connect(self.on_pushButton_clicked_6)
and the error am getting is
Traceback (most recent call last):
File "C:/Users/pc/PycharmProjects/presents/Main.py", line 1, in <module>
from PyQt5 import QtCore, uic, QtWidgets
ModuleNotFoundError: No module named 'PyQt5'

I find out that I can just use the available tool in PyCharm which is the IDE am using for python. By just clicking the red underlined word PyQt5 in this case and a red bulb will appear to the left end of the line >> click the drop down that appear and select install package PyQt5. it installs the required staff again and everything works fine then.

It sounds like the Python Console and your project are running two different Python Interpreters.
When you start the Python Console the top line should list the interpreter it's using. This is the one you installed PyQt5 to.
Go to: File -> Settings -> Project: xxxxx -> Project Interpreter and change it to the one that's in your Python Console. (Note you may need to add another interpreter by clicking on the gear to the right of the text box listing the interpreters)

Installing PyQt5 like this worked for me:
python -m pip install PyQt5
You can try to reinstall PyQt5 like this:
pip uninstall PyQt5
python -m pip install PyQt5

Related

Unable to import QtGui, QtWidgets modules of PyQt5/PySide in WinPE

I'm developing a tool to be used in WinPE and have been facing an issue while using PySide2/PyQt5 in WinPE environment.
While importing QtGui, it says ImportError: DLL load failed while importing QtGui: The specified module could not be found.
But importing QtCore is successful.
If I use the same environment in another Windows machine it is successful.
I also developing a pyqt5 program run in winpe.
using pyinstaller convert it to exe and run successfully in a new win7 machchine.
when start at win10 pe the command line says below message.
The specified module could not be found.
I found one solution is using specific version of PyQT5 from below url
pip install PyQT5==5.9
https://stackoverflow.com/a/51821319/7324168

Python - PyQt5 [PyQt5.QtWidgets import QApplication 'No Module']

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

advice about the PyQt5

Im working on application design using Qt Design. the design completed so now i want to connect it with Python 3.6.4 using pycharm. and import PyQt5. i already installed PyQt5 as you can see.
PS C:\Users\Tariq> pip install pyqt5
Requirement already satisfied :pyqt5 in
c:\users\tariq\appdata\local\programs\python\python36-32\lib\site-packages
Requirement already satisfied: sip<4.20,>=4.19.4 in
c:\users\tariq\appdata\local\programs\python\python36-32\lib\site-packages
(from pyqt5)
also i installed PyQt5 inside pycharm as you can see in the picture.
Press enter to show the image that PyQt5 installed inside pycharm
My Problem that the PyQt5 unknown for pycharm and this error appear
from PyQt5.QtWidgets import*
ModuleNotFoundError: No module named 'PyQt5
'
The way that has always worked for me is below.
from PyQt5 import QtCore, QtGui, QtWidgets
This maybe due to the way you set up your environment variable add this c:\Python3*\Script,C:\Python3*\Lib\site-packages\, and C:\Python34\Lib\site-packages\PyQt5\ in your environmental path, hope it works. '*` is the version of python e.g Python34

PyQt5 crashes if I import QtWebEngineWidgets

I created a new Anaconda environment with Python 3.6. I installed PyQt5 with pip install PyQt5. I have this butt-simple program:
from PyQt5 import QtWidgets
#from PyQt5 import QtWebEngineWidgets
app = QtWidgets.QApplication([])
As written, it runs (and does nothing). If I uncomment the QtWebEngineWidgets line, it crashes. If I leave that line uncommented, but comment out the final line, it no longer crashes. In other words, it crashes when trying to create the application, but only if I previously tried to import QtWebEngineWidgets. Importing QtWebEngineWidgets itself doesn't cause a crash unless I try to create an application.
I'm running this on Windows 7. The crash is a "hard" crash: it's not a Python exception, but a Windows popup saying "Python has stopped working". The info says that the crash is in "atio6axx.dll". Googling around I see some hints that there could be some sort of conflict between Qt and my graphics driver, but I don't know how to debug it, let alone fix it. (I have an embedded graphics controller that shows as ATI Radeon HD 4250.)
conda list qt shows:
PyQt5 5.8.2 <pip>
What can I do to be able to use QtWebEngine successfully?
In my experience this issue has nothing to do with PyQt being installed using both pip and anaconda, although this would cause an problem too. If you only have pyqt installed on Anaconda the following code my cause a hard crash:
from qtpy import QtWidgets
from qtpy import QtWebEngineWidgets
app = QtWidgets.QApplication([])
We started experiencing this on a number of computers after an "upgrade" to windows 10, and noticing Spyder stopped working. It exited without an error message. The IT guys tracked it down to the graphics card.
Solutions: downgrade pyqt to version 5.6: conda install pyqt=5.6
I'm seeing this behavior on a windows 10 machine currently as well.
I use qtpy as well but have done this same example in just PyQt5.
Downgraded to 5.6 changes other behavior li

PyQt5 Maya 2017

Having some trouble setting up PyQt5 with Maya 2017. I have successfully installed PyQt5 on my mac and I can write standalone applications, but when I try to import PyQt5 modules in the Maya Script Editor using (for example)
from PyQt5 import QtWidgets
I get the following error :
Error: line 1: ImportError: file <maya console> line 1: No module named PyQt5
Not very experienced with using Python in Maya, is there some configuration I have to do? Also, does PyQt5 work with Maya 2016?
Maya won't ship with pyqt and you need to build your own version of pyqt for maya with mayapy. You local install of pyqt won't get loaded to maya so need to compile your version yourself. This link will give a insight of that http://justinfx.com/2011/11/09/installing-pyqt4-for-maya-2012-osx/. Although maya 2017 shipping with PySide2 and you can always use Pyside rather than pyqt.
like
from PySide2 import QtWidgets
Hope this helps.
If you want your scripts and UIs to work on either Maya 2016 or 2017 and above, I would suggest using the Qt.py package from Marcus Ottoson.
You can find it here.
You can just install it somewhere on your computer and add its path to the 'path' variable in your environment variables, you can then just do:
from Qt import QtWidgets, QtCore, QtGui
You can then write your UIs as you would in PySide2, and they will work on all versions of Maya because Qt.py is just a wrapper choosing the proper binding available on your machine, whether it is Pyside, Pyside2, Qt5, Qt4.

Categories