[Arch Linux] Installing PyQt5 in a virtualenv
Jul 21, 2015
After learning about virtualenv, the first thing I do when I want to start a new project in Python is setting up a new virtual environment to carefully specify the libraries and packages I will need. Today I was trying to setup a project and use Qt5 as the graphical interface library, and I started searching about how to make it the easiest way.
There are a couple of paths I could go here: virtualenv has a parameter called –system-site-packages that will copy all packages from your system to your virtual environment. This option will, at least, make your virtual environment a little polluted, and I don’t want that. Another option is to compile it yourself. I was ready to do that when I found another faster and simpler way.
The Trick
The trick is copying only the specific files from the system that will make your virtual environment be able to “import PyQt5” into your project. And I discoverd how to do that here.
Although the example there refers to Ubuntu locations,
it’s pretty easy to find out that in ArchLinux python-pyqt5
files are located in
/usr/lib/python3.4/site-packages/ and the only
.so file from sip appears to be
/usr/lib/python3.4/site-packages/sip.so. All I
did was to copy the PyQt5 folder as long as the
sip.so file to my
virtual-environment-path/lib/python3.4/site-packages
and I was able to use PyQt5 from there:
sudo pacman -S python-pyqt5
virtualenv3 -p python3 env
LIBDIR="$HOME/path/to/virtual/environment/lib/python3.4/site-packages"
cp -r /usr/lib/python3.4/site-packages/sip.so "$LIBDIR"
cp -r /usr/lib/python3.4/site-packages/PyQt5 "$LIBDIR/PyQt5"After that, I’m successfully able to run a PyQt5 program from the virtual environment.