Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install PyQt5 on Ubuntu with python3. Steps to set up PyQt5 (ubuntu). With python code generation


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


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


Code Generation

Create file.


import subprocess
import sys

child = subprocess.Popen(['pyuic5' ,'-x',sys.argv[1]],stdout=subprocess.PIPE)


$ chmod +x

Create a symlink:

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

Desktop Entry

[Desktop Entry]
Name=Qt5 Designer

Name[en_US]=Qt5 Designer

[Desktop Action NewWindow]
Name=Open a New Window

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

Copy link

umbe1987 commented Aug 9, 2018

This helped me a lot setting the right qtdesigner! Thanks for sharing this gist! Kind regards, Umberto

Copy link

ravi97garg commented Sep 4, 2018

Unable to launch /usr/lib/qt5/bin/uic.
screenshot from 2018-09-05 00-02-30

Please help!!

Copy link

ChrisVilches commented Sep 16, 2018

I'm using Linux Mint and the first command pip3 install --user pyqt5 told me I need the SIP software/library. So I downloaded it from this page:

By following the steps, I achieved the make step, and it also threw an error telling me Python.h wasn't available, so I had to install sudo apt-get install python3-dev. Then ran make again and worked. Then the pip3 install --user pyqt5 command worked.

Copy link

ujjwal96 commented Oct 2, 2018

@ravi97garg here write
sudo ln "/usr/lib/qt5/bin/uic"

Copy link

mraehanakbar commented Mar 1, 2019

worked thanks

Copy link

CyberSinister commented May 8, 2019

How do I add PyQt5 to Qt Creator? I'm lost. I've spent 4 hours on this and now I've given up. Any help?

Copy link

FangliangBai commented Jun 3, 2019

How do I add PyQt5 to Qt Creator? I'm lost. I've spent 4 hours on this and now I've given up. Any help?

What do you mean by adding PyQt5 to Qt Creator?
They work separately.
Usually, You can use Qt Creator (or Qt Designer) to draw the UI and generate .ui file, e.g. window.ui. Then you use PyQt5 to convert the window.ui file to a file. Then you should write your code based on the and don't need window.ui anymore, unless you modified it (you should redo the conversion).

Copy link

MrFlava commented Jul 18, 2019

Help me! How to fix this problem?

Copy link

madhuniha commented Jul 18, 2019

when i run qtchooser -run-tool=designer -qt=5
i get
QXcbConnection: Could not connect to display
Aborted (core dumped)
What must have gone wrong? I created a new virtual environment and followed your steps.

Copy link

ujjwal96 commented Jul 18, 2019

@MrFlava Looks like you either you don't have python3 in /usr/bin or there's some error in your file

Copy link

ujjwal96 commented Jul 18, 2019

@madhuniha This seems like a bug. Try running
$ xvfb-run -- qtchooser -run-tool=designer -qt=5

Ref. wkhtmltopdf/wkhtmltopdf#2037 (comment)

Copy link

MrFlava commented Jul 18, 2019

@ujjwal96 you mean this?

Copy link

Sokom141 commented Sep 26, 2019

Thank you so much! This worked, as opposed to other methods.

Copy link

Ahsanrao237 commented Dec 8, 2019

Q: how to convert .ui file into .py file?
Ans: Open terminal in the folder where your ui file present, then write this command.
pyuic -x [FILENAME].ui -o [FILENAME].py

Copy link

aanastasiou commented Jan 8, 2020

So, from the point of view of running python within a virtual environment, it is very likely that all steps to get pyqt5 will work, except the bit that used to bring qt-designer in. If the system has Qt5 installed, it seems to have all the libraries required for it installed too and even if you don't have pyqt5 installed on the base system, the qtchooser way of launching qtdesigner from above will work.

Therefore, a key component here is qtchooser.

The compiler will become available immediately within the virtualenv once you install pyqt5 there.

It would be great if the settings to launch the designer (in terms of setting up environment variables) where applied by one of the pip packages :/

Copy link

mohamadjalali commented Jan 17, 2020

Which path do I choose to save the file?!?
After creating the file by entering this command
$ sudo ln "/usr/lib/x86_64-linux-gnu/qt5/bin/uic"
I have the following error !!!
ln: failed to create hard link '/usr/lib/x86_64-linux-gnu/qt5/bin/uic': File exists

Copy link

carlos-antonio-dias commented Feb 5, 2020

Hi everyone I got stuck right at the first command(pip3 install --user pyqt5) which show there error:
Command "python egg_info" failed with error code 1 in /tmp/pip-build-cvndyrvb/pyqt5/
I went through:

And none of it helped. Any ideas?

Copy link

sahilparekh commented Feb 16, 2020

Hi everyone I got stuck right at the first command(pip3 install --user pyqt5) which show there error:
Command "python egg_info" failed with error code 1 in /tmp/pip-build-cvndyrvb/pyqt5/
I went through:

And none of it helped. Any ideas?

use pip3 install --user pyqt5==5.14

Copy link

wrishel commented Feb 26, 2020

Top-notch tutorial in that it works without a lot of knowledge about Ubuntu! I think it's possible that the Desktop Entry section is no longer needed. If you decide to keep it, it needs a minor update.

When I have finished the tutorial and Show Application in Ubu 18, I see two for designer. One has a generic icon and the other has an icon specific to Qt.
Screenshot from 2020-02-25 17-36-49
The .desktop file with is in /usr/share/applications/designer-qt5.desktop with a modification date in 2018 so I suppose it was installed along with Qt. The .desktop file for the the item with the generic logo is in the one I created following the tutorial.

So, two issues:

  1. if the desktop files are installed with QT do we really need the Desktop Entry section in the tutorial?
  2. if you do keep that section I suggest changing "Icon=designer" to "Icon=designer-qt" since this creates the desktop entry with Qt's icon.

This is great work. Thanks again.

Copy link

DurgaPrasadMyWay commented Mar 11, 2020

Thank you.

Copy link

ghost commented Mar 13, 2020

God bless you

Copy link

livvyvi3 commented Apr 5, 2020

When I run the last command I am getting this error "E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?". How do I fix this please

Copy link

LionOpeter commented May 6, 2020

I also get "Command "python egg_info" failed with error code 1 in /tmp/pip-build-dm9du9iv/PyQt5/" like sahilparekh did.
We are getting it when attempting to use the first command: pip3 install --user PyQt5
Looks like it searches for the file /tmp/pip-build-dm9du9iv/PyQt5/
Once not found - it fails.
Complete outpu:

Collecting PyQt5
  Using cached
    Complete output from command python egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python3.6/", line 452, in open
        buffer = _builtin_open(filename, 'rb')
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-dm9du9iv/PyQt5/'
Command "python egg_info" failed with error code 1 in /tmp/pip-build-dm9du9iv/PyQt5/

Copy link

SteveF161 commented Sep 2, 2020

I'm also getting "python egg_info" failed with error code 1 ..." . Did anyone get a fix for this yet? I tried "pip3 install --user pyqt5==5.14" as mentioned above but same problem?

Copy link

LionOpeter commented Sep 4, 2020

Hi @SteveF161,
I don't know how I finally got passed the error as it was some time ago.
But I can show the output I get now as it might give you a clue:

$ pip3 install --user PyQt5
Requirement already satisfied: PyQt5 in /home/liron/.local/lib/python3.6/site-packages (5.14.2)
Requirement already satisfied: PyQt5-sip<13,>=12.7 in /home/liron/.local/lib/python3.6/site-packages (from PyQt5) (12.7.2)
WARNING: You are using pip version 20.1; however, version 20.2.2 is available.
You should consider upgrading via the '/usr/bin/python3 -m pip install --upgrade pip' command.

Copy link

sir-pietruch commented Oct 8, 2020

Hello @SteveF161 I can confirm @LionOpeter 's suggestion to update pip3
pip3 install --upgrade pip
worked for me on Ubuntu 18.04 LTS

Copy link

DungLeMTA commented Apr 9, 2021

I got this error, someone can help me:

/usr/bin/python3.8 /home/dung/PycharmProjects/detai/
QObject::moveToThread: Current thread (0x19ebfd0) is not the object's thread (0x20abd70).
Cannot move to target thread (0x19ebfd0)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/dung/.local/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Copy link

chrswp commented Jul 17, 2021

Crystal clear instruction how to install PyQt5. Works like a charm!

Thanks for the instruction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment