1
votes

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'
3

3 Answers

3
votes

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.

2
votes

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)

1
votes

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