0

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

  • Have you used `sudo pip install PyQt5` or installed globally without a virtualenv? – Hemant Jan 11 '21 at 10:03
  • I used this command and the result is that the `requirement already satisfied` and installed it globally but still it is not being imported in the sublime text. Although it is working fine when imported in terminal – helluhellu papa Jan 11 '21 at 10:21
  • I think the issue is that you have installed PyQt5 using sudo(available for sudo user) and your sublime text is running your python file with a non sudo user. Try running `sudo python ` – Hemant Jan 11 '21 at 10:43
  • It worked but the sublime text is still showing me the error. Although I run this `sudo python ` in the terminal and executed the sublime code but how can I remove this `module error` in the sublime text – helluhellu papa Jan 11 '21 at 10:57
  • i have composed an answer for your question, have a look – Hemant Jan 11 '21 at 11:16

1 Answers1

0

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

Hemant
  • 1,127
  • 1
  • 10
  • 18