I\'m using Virtualenv with profit on my development environment with web.py
, simplejson
and other web oriented packages.
I\'m going to develop
Expanding on Aaron Digulla's answer, using git to get the file list right can be really handy. I usually do something like this (from an msysGit shell):
# Create temp git repo for the pristine Python installation
$ cd /c/Python27
$ git init -q
$ git add .
$ git commit -qm "Initial commit"
Then run the installer for PyQt4 (or whatever). After that, make a tarball of the files that the installer added and delete the temp git repo, as follows:
# Stage the PyQt4-installed files and feed a list of their names to tar
# (note that there's no need to actually commit them)
$ git add --all
$ git diff --cached --name-only | tar -jcf pyqt4.tar.bz2 --files-from=-
$ rm -rf .git
Then you can run PyQt4's uninstaller (if you don't want to clutter up your system Python), and simply untar pyqt4.tar.bz2
into your virtualenv folder. If you're already comfortable using git, this is a great way to ensure you get all the PyQt4-installed files.
NOTE: Installing PyQt4 using the packaged installer also installs SIP. If you actually want to use this SIP to create bindings for your own C/C++ code inside your virtualenv, you'll want to modify the paths in the sipconfig.py
file after you copy it over. Otherwise, SIP's build system will still be pointing at the system Python folder (e.g., C:\Python32
or whatever), which won't work if you delete all the PyQt4-installed files from there. (If you don't have any intention of using SIP yourself, you can probably skip this.)
Linux debian, python 2.7:
sudo apt-get install python-qt4
ln -s /usr/lib/python2.7/dist-packages/PyQt4/ ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
ln -s /usr/lib/python2.7/dist-packages/sip.so ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
For those who want to use PyQt4 in a Python 3 virtualenv (on OSX) you first install PyQt4 and SIP (I will use homebrew)
$ brew install python3
$ brew install sip --with-python3
$ brew install pyqt --with-python3
Then create your virtual environment
$ virtualenv ...
Finally symlink (change the versions of SIP, PyQt4 and Python for those installed on your machine)
$ ln -s /usr/local/Cellar/sip/4.15.5/lib/python3.4/site-packages/*.* ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python3.4/site-packages/
$ ln -s /usr/local/Cellar/pyqt/4.10.4/lib/python3.4/site-packages/PyQt4/*.* ~/{VIRTUALENVHOME}/{VIRTUALENVNAME}/lib/python3.4/site-packages/PyQt4
For PySide 1.2.1 and Ubuntu 12.4
Install compilers, Qt related, python sources
sudo apt-get install cmake qt4-qmake qt-sdk python-dev
Create virt env withvirtualenvwrapper
Be ready for compiling Qt (~30 min)
$ mkvirtualenv ve_name
(ve_name)$ pip install PySide
Test
$ python -c "from PyQt4 import QtCore; print QtCore.PYQT_VERSION_STR"
4.9.1
I have the same problem. I use virtualenvwrapper, so I wrote this script to create a link to PyQt in every new virtual environment. Maybe is useful for someone else:
#!/bin/bash
# This hook is run after a new virtualenv is activated.
# ~/.virtualenvs/postmkvirtualenv
LIBS=( PyQt4 sip.so )
PYTHON_VERSION=python$(python -c "import sys; print (str(sys.version_info[0])+'.'+str(sys.version_info[1]))")
VAR=( $(which -a $PYTHON_VERSION) )
GET_PYTHON_LIB_CMD="from distutils.sysconfig import get_python_lib; print (get_python_lib())"
LIB_VIRTUALENV_PATH=$(python -c "$GET_PYTHON_LIB_CMD")
LIB_SYSTEM_PATH=$(${VAR[-1]} -c "$GET_PYTHON_LIB_CMD")
for LIB in ${LIBS[@]}
do
ln -s $LIB_SYSTEM_PATH/$LIB $LIB_VIRTUALENV_PATH/$LIB
done
link to gist
Easiest way is to install this : vext.pyqt4
This will add the single system PyQt4
package to your virtualenv.
Ubuntu 16.04 usage:
sudo apt install python3-pyqt4
mkvirtualenv --python=python3.5 venv
pip install --no-use-wheel vext.pyqt4