Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

python - How to make the import PyQt5 working in sublime text?

I have installed PyQt5 and PyQt5-tools using command prompt and pip install PyQt5 then pip install PyQt5-tools and sudo apt-get install python3-pyqt5 everything installed fine I then put in the following code

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
 
def window():
    app = QApplication(sys.argv)
    win = QMainWindow()
    win.setGeometry(200, 200, 300, 300)
    win.setWindowTtitle("Darts Scoreboard")
 
    win.show()
    sys.exit(app.exec_())
 
window()

but get the following traceback

Traceback (most recent call last):
  File "/home/bilal/Documents/hello.py", line 1, in <module>
    from PyQt5 import QtWidgets
ImportError: No module named PyQt5
[Finished in 0.1s with exit code 1]
[shell_cmd: python -u "/home/bilal/Documents/hello.py"]

I have checked all sort of youtube help advice and instructions and nothing seems to work can someone please please help


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The solution for such a scenario when non sudo user is unable to access package, would be to remove the package with sudo privilege and reinstalling it as non root user, like this


sudo pip uninstall PyQt5

and reinstalling it without sudo privileges

pip install PyQt5

I would highly suggest you to use virtualenv in python check this out, which you can activate whenever needed.

for setting up virtual env for sublime have a look at this


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...