Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save r00tdaemon/1dcd57542bdaf3c9d1b0dd526ccd44ff to your computer and use it in GitHub Desktop.
Save r00tdaemon/1dcd57542bdaf3c9d1b0dd526ccd44ff to your computer and use it in GitHub Desktop.
Install PyQt5 on Ubuntu with python3. Steps to set up PyQt5 (ubuntu). With python code generation

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

@mohamadjalali
Copy link

mohamadjalali commented Jan 17, 2020

Which path do I choose to save the uic.py file?!?
After creating the uic.py file by entering this command
$ sudo ln uic.py "/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

@carlos-antonio-dias
Copy link

Hi everyone I got stuck right at the first command(pip3 install --user pyqt5) which show there error:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-cvndyrvb/pyqt5/
I went through:
facebook/prophet#418
https://superuser.com/questions/241865/updating-python-on-ubuntu-system

And none of it helped. Any ideas?

@sahilparekh
Copy link

Hi everyone I got stuck right at the first command(pip3 install --user pyqt5) which show there error:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-cvndyrvb/pyqt5/
I went through:
facebook/prophet#418
https://superuser.com/questions/241865/updating-python-on-ubuntu-system

And none of it helped. Any ideas?

use pip3 install --user pyqt5==5.14

@wrishel
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.

@DurgaPrasadMyWay
Copy link

Thank you.

Copy link

ghost commented Mar 13, 2020

God bless you

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

@LionOpeter
Copy link

I also get "Command "python setup.py 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/setup.py
Once not found - it fails.
Complete outpu:

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

@SteveF161
Copy link

I'm also getting "python setup.py 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?

@LionOpeter
Copy link

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.

@sir-pietruch
Copy link

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

@DungLeMTA
Copy link

I got this error, someone can help me:

/usr/bin/python3.8 /home/dung/PycharmProjects/detai/main.py
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)

@chrswp
Copy link

chrswp commented Jul 17, 2021

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

Thanks for the instruction.

@smnlin
Copy link

smnlin commented Sep 7, 2022

This still works on ubuntu 20.04!!!
Thank you so much!!!

@FariasMarina
Copy link

Thank you, you helped me a lot

@amitpande74
Copy link

Hi @ujjwal96 ,

I am trying to install a ML package iLearnPlus
I made a separate conda environment on Ubuntu 22-04 and followed all the instructions while installing PyQt5 which you have recommended here.
I am still getting an error:

python iLearnPlus.py 
Traceback (most recent call last):
  File "iLearnPlus.py", line 5, in <module>
    from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QDesktopWidget, QLabel, QHBoxLayout, QMessageBox, QAction, QFileDialog)
ImportError: /home/amit/miniconda3/envs/ilearn/lib/python3.8/site-packages/PyQt5/QtWidgets.abi3.so: undefined symbol: _ZdlPvm, version Qt_5

Kindly help. Regards.

@MikeyBeez
Copy link

Ha! How funny that you got 132 stars for forking a gist of mine that got none. That's the story of my life. ;)

@wrishel
Copy link

wrishel commented May 3, 2024 via email

@MikeyBeez
Copy link

That's funny. I forked yours. I'm getting old.

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