简体   繁体   中英

How to install the PyQt5?

I have been searching to resolve this problem for two days. I tried a lot of ways, searched the answer on google, but didn't find a single solution to the problem. I want to know why PyQt5 is not working even if it is installed.

Although the pip show option is working, and the pip install option is already satisfied but it is still causing the issue and the code is not executing.

Code

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys

def window():
    app = QApplication(sys.argv)
    win = QMainWindow()
    win.setGeometry(1000, 200, 300, 300)
    win.setWindowTitle("ibilalkayy")

    win.show()
    sys.exit(app.exec_())
window()

pip show PyQt5 result

Name: PyQt5
Version: 5.15.2
Summary: Python bindings for the Qt cross platform application toolkit
Home-page: https://www.riverbankcomputing.com/software/pyqt/
Author: Riverbank Computing Limited
Author-email: info@riverbankcomputing.com
License: GPL v3
Location: /usr/lib/python3/dist-packages
Requires: PyQt5-sip
Required-by: PyQtWebEngine

pip install PyQt5==5.15.2

Requirement already satisfied: PyQt5==5.15.2 in /usr/lib/python3/dist-packages (5.15.2)
Requirement already satisfied: PyQt5-sip<13,>=12.8 in /usr/lib/python3/dist-packages (from PyQt5==5.15.2) (12.8.1)

Code execution and error

python3 /Path/to/tutorial.py
Traceback (most recent call last):
  File "/Path/to/tutorial.py", line 1, in <module>
    from PyQt5 import QtWidgets
ModuleNotFoundError: No module named 'PyQt5'

Try to change your path python3 /Path/to/tutorial.py Traceback (most recent call last): File "/Path/to/tutorial.py", line 1, in <module> from PyQt5 import QtWidgets ModuleNotFoundError: No module named 'PyQt5' To /usr/lib/python3/dist-packages Ok stay happy

Try to install a PyQt5 with pip3 command.

sudo pip3 install PyQt5==5.15.2

There are 2 cases that can happen:

  1. When you're doing this on a new IDE
  2. When you're running this file in a new app,(Example, you're running this on PyCharm, etc.)

This generally happens when your IDE or the output app is new and you've not set python in path. So, if you have python already installed, try running the file in CMD or adding python to path.

Aside from what everyone else has mentioned, there's one more scenario which I suspect might be the case. Make sure you haven't given any of the folders or directories included in the path of your file ('tutorial.py') the same name as the module (ie 'PyQt5').

That's all I have to add. I agree this "answer" would be better suited as a comment but I don't have enough reputation so this is the only way I could bring up this point...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM