Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named PytQt5

Tags:

python

pyqt5

following are my python, qt and sip versions

root@thura:~# python -V Python 2.7.3 root@thura:~# qmake --version QMake version 3.0 Using Qt version 5.0.2 in /usr/lib/i386-linux-gnu root@thura:~# sip -V 4.15.3 

I tried to import the PyQt5 by following by this

from PyQt5.QtWidgets import QtGui, QtCore 

I got the following error

ImportError: No module named PyQt5.QtWidgets

How can I solve this error.

Updated =====================

When I tried to PyQt4, I got following error.

from PyQt4.QtCore import pyqtSlot as Slot RuntimeError: the sip module implements API v10.0 to v10.1 but the PyQt4.QtCore module requires API v8.1

Updated 2013-12-20 ======================================

1) download sip-4.15.3.tar.gz from here

2) extract sip-4.15.3.tar.gz

3) copy sip-4.15.3 to /home/thura

4) type "cd /home/thura/sip-4.15.3"

5) type "python configure.py", press enter, follow the instructions (type yes and press enter)

6) type "make", press enter and type "make install", press enter

7) download PyQt-gpl-5.1.1.tar.gz from here

8) extract PyQt-gpl-5.1.1.tar.gz

9) copy PyQt-gpl-5.1.1 folder to /home/thura folder.

10) type "cd /home/thura/PyQt-gpl-5.1.1"

11) type "python configure.py", press enter, following the instructions (type yes and press enter)

12)type "make", press enter and type "make install", press enter

update 2013-12-20 =====================

After redo it again. I got the following error

make[2]: Entering directory `/home/thura/PyQt/qpy/QtDBus' make[2]: Nothing to be done for `install'. make[2]: Leaving directory `/home/thura/PyQt/qpy/QtDBus' make[1]: Leaving directory `/home/thura/PyQt/qpy' cd QtCore/ && ( test -e Makefile || /usr/lib/i386-linux-gnu/qt5/bin/qmake /home/thura/PyQt/QtCore/QtCore.pro -o Makefile ) && make -f Makefile install make[1]: Entering directory `/home/thura/PyQt/QtCore' g++ -c -pipe -O2 -Wall -W -D_REENTRANT -fPIC -DSIP_PROTECTED_IS_PUBLIC -Dprotected=public -DQT_NO_DEBUG -DQT_PLUGIN -DQT_CORE_LIB -I/usr/share/qt5/mkspecs/linux-g++ -I. -I/usr/local/include/python2.7 -I../qpy/QtCore -I/usr/include/qt5 -I/usr/include/qt5/QtCore -I. -o sipQtCoreQtWindowStates.o sipQtCoreQtWindowStates.cpp In file included from sipQtCoreQtWindowStates.cpp:24:0: sipAPIQtCore.h:28:17: fatal error: sip.h: No such file or directory compilation terminated. make[1]: *** [sipQtCoreQtWindowStates.o] Error 1 make[1]: Leaving directory `/home/thura/PyQt/QtCore' make: *** [sub-QtCore-install_subtargets-ordered] Error 2 
like image 547
Thu Ra Avatar asked Dec 19 '13 03:12

Thu Ra


People also ask

How to fix No module named PyQt5?

The Python "ModuleNotFoundError: No module named 'PyQt5'" occurs when we forget to install the PyQt5 module before importing it or install it in an incorrect environment. To solve the error, install the module by running the pip install PyQt5 command.

How do I import QtGui?

Enter the mainloop of application by app.Import QtCore, QtGui and QtWidgets modules from PyQt5 package. Create an application object of QApplication class. Add a QLabel object and set the caption of label as "hello world". Define the size and position of window by setGeometry() method.

How do I download PyQt5?

To install PyQt on Windows there are a few steps you need to take. First use the installer from the qt-project website, from qt to install PyQt. Next you want to install a Python version 3.3 or newer. Check the box to add all of the PyQt5 extras.


2 Answers

If you are on ubuntu, just install pyqt5 with apt-get command:

    sudo apt-get install python3-pyqt5   # for python3 

or

    sudo apt-get install python-pyqt5    # for python2 

However, on Ubuntu 14.04 the python-pyqt5 package is left out [source] and need to be installed manually [source]

like image 191
qtopierw Avatar answered Sep 29 '22 08:09

qtopierw


pip install pyqt5 for python3 for ubuntu

like image 32
Durgesh Kumar Avatar answered Sep 29 '22 08:09

Durgesh Kumar