2

Moving Flask app from local environment to Ubuntu 14.04. Getting 'NameError: 'QtWidgets' is not defined"

Have done the following:

sudo apt-get install python3-pyqt5 

verified this with following command:

apt-cache policy python3-pyqt5

        result: "python3-pyqt5:  
                    Installed: 5.2.1+dfsg-1ubuntu1  
                    Candidate: 5.2.1+dfsg-1ubuntu1  
                    Version table:  
                  ***5.2.1+dfsg-1ubuntu1 0  
                        500 http://mirrors.digitalocean.com/ubuntu/ trusty/main amd64 Packages"

tried following command from python command line:

from PyQt5 import QtWidgets 

got following response:

ImportError: No module named 'PyQt5'

I'll admit to being relatively new to this, so it's probably something obvious to experienced folks. In any event thanks for any insights you can offer.

Zanna
  • 69,223
  • 56
  • 216
  • 327
psanc
  • 21
  • 1
  • 1
  • 4

1 Answers1

2

Indeed it is something simple: QtWidgets , i.e. non-singular

>>> from PyQt5.GUI import QtWidget
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'PyQt5.GUI'
>>> from PyQt5 import QtWidgets
>>>

Also, ensure that you're calling correct interpreter. You've installed PyQt5 for Python3, so use python3:

$ python
Python 2.7.12 (default, Jul  1 2016, 15:12:24) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5 import QtWidgets
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PyQt5
>>> 

$ python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5 import QtWidgets
>>>
Sergiy Kolodyazhnyy
  • 103,293
  • 19
  • 273
  • 492
  • Thanks for the response. Turns out I do use QtWidgets (plural); I errored in my question write-up. Net-Net: I still have the problem. I'll edit the question to fix the issue you pointed out. Thanks again. – psanc Nov 03 '16 at 18:49
  • @psanc See my edit. Here's my suggestion: go back and review basics. Don't jump to GUI programming too fast. Train your attention to key details. – Sergiy Kolodyazhnyy Nov 03 '16 at 19:54
  • Yes, agree that it's good to go back and review basics (especially given my experience level). I've double checked and am using the correct interpreter: Python 3.4.3 – psanc Nov 03 '16 at 20:10