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
  • 72,312
psanc
  • 21

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