Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install PyQt5 in Python 3 (Ubuntu 14.04)

I need to port some code that's Python2+PyQt4 to Python3+PyQt5.

I started installing pip3

sudo apt-get install python3-pip 

Works great. Tried

sudo pip3 install PyQt5 Downloading/unpacking PyQt5   Could not find any downloads that satisfy the requirement PyQt5 Cleaning up... No distributions at all found for PyQt5 

Online I find the following steps:

http://pyqt.sourceforge.net/Docs/PyQt5/installation.html

But they are too many. What's the easiest way to Install PyQt5 along with Python3 in Ubuntu 14.04 ?

like image 527
eri0o Avatar asked Apr 21 '16 00:04

eri0o


People also ask

How do I run PyQt5 on Ubuntu?

Install PyQt5 via apt In Ubuntu you can install either from the command line or via "Software Center". The package you are looking for is named python3-pyqt5 . After install is finished, you should be able to run python (or python3 ) and import PyQt5 without errors.

Which Python version supports PyQt5?

PyQt5 wheels are specific to a particular version of Python. Only Python v3. 5 and later is supported. Wheels are provide for 32- and 64-bit Windows, 64-bit OS X and 64-bit Linux.

How do I download PyQt Python?

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. It's not necessary to compile everything from source, you can install all the required packages with the installer.

What is PIP PyQt5?

PyQt5 is a comprehensive set of Python bindings for Qt v5. It is implemented as more than 35 extension modules and enables Python to be used as an alternative application development language to C++ on all supported platforms including iOS and Android.


2 Answers

Why not simply install it via apt-get?

sudo apt-get install python3-pyqt5

Otherwise you'd have to compile PyQt (and potentially Qt) by hand, which is cumbersome.

like image 124
The Compiler Avatar answered Oct 16 '22 09:10

The Compiler


Well I documented the steps for Installing pyqt5 with qt designer and code generation here: https://gist.github.com/ujjwal96/1dcd57542bdaf3c9d1b0dd526ccd44ff

Installation

pip3 install --user pyqt5   sudo apt-get install python3-pyqt5   sudo apt-get install pyqt5-dev-tools sudo apt-get install qttools5-dev-tools 

Configuring to run from terminal

$ qtchooser -run-tool=designer -qt=5 

OR

Write the following in /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf

/usr/lib/x86_64-linux-gnu/qt5/bin /usr/lib/x86_64-linux-gnu 

Code Generation

Create uic.py file.

#!/usr/bin/python3  import subprocess import sys  child = subprocess.Popen(['pyuic5' ,'-x',sys.argv[1]],stdout=subprocess.PIPE)  print(str(child.communicate()[0],encoding='utf-8')) 

$ chmod +x uic.py 

Create a symlink:

$ sudo ln uic.py "/usr/lib/x86_64-linux-gnu/qt5/bin/uic" 

Desktop Entry

[Desktop Entry] Name=Qt5 Designer Icon=designer Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer Type=Application Categories=Application Terminal=false StartupNotify=true Actions=NewWindow  Name[en_US]=Qt5 Designer  [Desktop Action NewWindow] Name=Open a New Window Exec=/usr/lib/x86_64-linux-gnu/qt5/bin/designer 

save in ~/.local/share/application with .desktop extension

like image 45
Ujjwal Avatar answered Oct 16 '22 10:10

Ujjwal