So you want Qt5, but you have a lot of strict dependencies holding you back from going to Python 3. What to do? Go build everything yourself!
The following are steps based on a fresh install of Ubuntu 16.04, so adapt it per your needs.
First install the latest version of Qt. I was using the free open source edition. At the time of this post, the following was the set of commands given by Qt’s official website. I just downloaded the installation into my Downloads folder and ran it:
First download the installer:
1 2 |
cd ~/Downloads wget https://download.qt.io/official_releases/qt/5.9/5.9.2/qt-opensource-linux-x64-5.9.2.run |
Next, adjust the permissions and install Qt:
1 2 |
chmod +x qt-opensource-linux-x64-5.9.2.run ./qt-opensource-linux-x64-5.9.2.run |
Now, that should have installed Qt5.x on your Ubuntu installation, it is time to install PyQt5 such that it uses Qt5 with Python 2.7. The key in this setup procedure is to build PyQt5 yourself.
First, SIP must be installed before proceeding with building PyQt5. You can download SIP from here. You can also just wget it!
1 |
https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.6/sip-4.19.6.tar.gz |
Now is where things get important, as I always prefer to use virtual environments when working with Python, rather than installing everything on the global Python installation. After extracting the file, make sure to run configure.py using your virtual environment’s Python!
1 2 3 |
tar xvf sip-4.19.6.tar.gz cd sip-4.19.6/ ~/path/to/virtualenv/python configure.py |
If the configuration was successful, the output should tell you that things related to SIP will be installed in your virtual environment’s folder, and NOT in your global Python that resides in /usr.
Now, running make and sudo make install will install SIP into your virtual environment folder, even if you are using sudo.
1 2 |
make sudo make install |
Now it is time to download PyQt5 and build it!
1 |
wget https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.9.2/PyQt5_gpl-5.9.2.tar.gz |
Configuration of PyQt5 is needed for building it. Again, using the right interpreter and the right parameters are key.
1 2 3 |
~/my_virtual_env_path/to/python configure.py -d ~/my_virtual_env_path/lib/python2.7/site-packages/ --sip=/my_virtual_env_path/bin/sip --sip-incdir=../sip-4.19.3/siplib/ --qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake make make install |
Now, assuming there are no errors, you should be able to run ‘import PyQt5’ in your virtual environment running Python 2.7!
Good afternoon,
I get an error when I run the next comand: “~/path/to/virtualenv/python configure.py”
I have changed the path and write my virtualenv: “~/prefix/lib/python2.7” but it gives an error: “~/prefix/lib/python2.7 is a directory”
How can I fix it?
Thank you for the attention,
Unai
With your virtualenv activated, can you tell me what your console says when you type:
which python
Thanks!
(python2.7ws) qwe:~/python2.7ws/bin/python2.7 configure.py -d ~/python2.7ws/lib/python2.7/site-packages/ –sip=~/python2.7ws/bin/sip –sip-incdir=../sip-4.19.3/siplib/ –qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake
than i got the output: Usage: python configure.py [opts] [macro=value] [macro+=value]
configure.py: error: ambiguous option: –sip (–sip-module, –sipdir?)
You seem to have a single dash “-” in front of the sip argument.
i have this error
ricci@ricci-Latitude-E6510:~/Descargas/PyQt5_gpl-5.9.2$ python configure.py -d cd /usr/local/lib/python2.7/site-packages/ –sip=/usr/local/bin –sip-incdir=../sip-4.19.3/siplib/ –qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake
Usage: python configure.py [opts] [name=value] [name+=value]
configure.py: error: ‘../sip-4.19.3/siplib/’ is not a directory
@ricardo, Can you confirm that relative to the location that you are running that command, the folder ‘sip-4.19.3’ exists?
hi!
when I run the follw comand
[~/Desktop/rdpy-test/python2-PyQt5/bin/python configure.py -d ~/Desktop/rdpy-test/python2-PyQt5/lib/python2.7/site-packages/ –sip=~/Desktop/rdpy-test/python2-PyQt5/bin/sip –sip-incdir=../sip-4.19.14/siplib/ -qmake= ~/Qt/5.9.2/gcc_64/bin/qmake]
i get an next error: [configure.py: error: ‘~/Desktop/rdpy-test/python2-PyQt5/bin/sip’ is not an executable]
how can I fix it?
Can you confirm that sip exists in ‘~/Desktop/rdpy-test/python2-PyQt5/bin’ ?
I had the same error and the sip package was already installed within the bin folder of my venv. I ran the configure.py by omitting the –sip option and it worked.
Hello, Minsung.
Im running the command :
/home/tozadore/.virtualenvs/R-CASTLE/bin/python configure.py -d /home/tozadore/.virtualenvs/R-CASTLE/lib/python2.7/site-packages/ –sip=/home/tozadore/.virtualenvs/R-CASTLE/bin/sip –sip-incdir=../sip-4.19.3/siplib/ –qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake/
This is SIP 4.19.6 for Python 2.7.12 on linux2.
Usage: python configure.py [opts] [macro=value] [macro+=value]
And getting the error:
configure.py: error: ambiguous option: –sip (–sip-module, –sipdir?)
PS: I checked the single dash as KX and that isent the problem.
Thanks
Hi Daniel,
Check Kaaviya’s comment! Thanks!
Hi Min Sung,
I run the following command (omitting the –sip option):
~/virtualY/Stage/bin$ python configure.py -d ~/virtualY/Stage/lib/python2.7/site-packages/ –qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake
and i get this error :
Traceback (most recent call last):
File “configure.py”, line 923, in
main(sys.argv)
File “configure.py”, line 764, in main
for s in os.listdir(os.path.join(src_dir, “specs”)):
OSError: [Errno 2] No such file or directory: ‘/home/isir2/virtualY/Stage/bin/specs’
I’m not sure of which “configure.py” file i’m supposed to use.
I think that i did not understand that part in your tutorial :
~/path/to/virtualenv/python configure.py
Here i just copy+past the configure.py file that was on the sip directory to the bin directory. Pretty sure it’s the problem (i don’t have that configure.py file other way)
Thank you for your time