Is it possible to add PyQt4/PySide packages on a Virtualenv sandbox?

40,185

Solution 1

It should be enough to create an empty virtualenv and then copy the contents of the .../site-packages/PyQt4 directories into it.

I suggest to install PyQt4 once globally, make a copy of the directory, uninstall it and then use this trick to create VEs.

Solution 2

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

Solution 3

Linux debian, python 2.7:

  • Install python-qt4 globaly: sudo apt-get install python-qt4
  • Create symbolic link of PyQt4 to your virtual env ln -s /usr/lib/python2.7/dist-packages/PyQt4/ ~/.virtualenvs/myEnv/lib/python2.7/site-packages/
  • Create symbolic link of sip.so to your virtual envln -s /usr/lib/python2.7/dist-packages/sip.so ~/.virtualenvs/myEnv/lib/python2.7/site-packages/

Solution 4

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

Solution 5

I asked if it's possible to install PySide from within virtualenv on irc.freenode.net #pyside channel and got positive answer from hugopl. So I followed instructions from PySide Binaries for Microsoft Windows and it worked. The output is below.

Z:\virtualenv\pyside>Scripts\activate.bat

(pyside) Z:\virtualenv\pyside>where python
Z:\virtualenv\pyside\Scripts\python.exe

(pyside) Z:\virtualenv\pyside>easy_install PySide
install_dir Z:\virtualenv\pyside\Lib\site-packages\
Searching for PySide
Reading http://pypi.python.org/simple/PySide/
Reading http://www.pyside.org
Reading http://www.pyside.org/files/pkg/
Best match: PySide 1.0.0beta1qt471
Downloading http://www.pyside.org/files/pkg/PySide-1.0.0beta1qt471.win32-py2.6.exe
Processing PySide-1.0.0beta1qt471.win32-py2.6.exe
Deleting c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp\EGG-INFO\scripts\py
ide-uic-script.py
Deleting c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp\EGG-INFO\scripts\py
ide-uic.exe
creating 'c:\users\piotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg' and adding 'c:\users\
iotr\appdata\local\temp\easy_install-fvfa7e\PySide-1.0.0beta1qt471-py2.6-win32.egg.tmp' to it
creating z:\virtualenv\pyside\lib\site-packages\PySide-1.0.0beta1qt471-py2.6-win32.egg
Extracting PySide-1.0.0beta1qt471-py2.6-win32.egg to z:\virtualenv\pyside\lib\site-packages
Adding PySide 1.0.0beta1qt471 to easy-install.pth file
Installing pyside-uic-script.pyc script to Z:\virtualenv\pyside\Scripts
Installing pyside_postinstall.py script to Z:\virtualenv\pyside\Scripts
Installing pyside_postinstall.pyc script to Z:\virtualenv\pyside\Scripts
Installing pyside-uic-script.py script to Z:\virtualenv\pyside\Scripts
Installing pyside-uic.exe script to Z:\virtualenv\pyside\Scripts

Installed z:\virtualenv\pyside\lib\site-packages\pyside-1.0.0beta1qt471-py2.6-win32.egg
Processing dependencies for PySide
Finished processing dependencies for PySide

(pyside) Z:\virtualenv\pyside>python Scripts\pyside_postinstall.py -install
Generating file Z:\virtualenv\pyside\Scripts\qt.conf...
The PySide extensions were successfully installed.
Share:
40,185
systempuntoout
Author by

systempuntoout

I'm a software architect, living and working in Italy. My Google App Engine project: - StackPrinter

Updated on July 08, 2022

Comments

  • systempuntoout
    systempuntoout almost 2 years

    I'm using Virtualenv with profit on my development environment with web.py, simplejson and other web oriented packages.
    I'm going to develop a simple python client using Qt to reuse some Api developed with web.py.

    Does anybody here had succesfully installed PyQt4 with Virtualenv?
    Is it possible?

    I've downloaded all the binaries and have PyQt4 installed globally on my python2.6 directory.
    If I don't use --no-site--packages option, Virtualenv correctly includes PyQt4 in my new sandbox but, obviously, with all the global packages that I don't need.

    Is there a clean way to prepare a new sandbox with --no-site--packages option and then add PyQt4 or PySide using pip, easy_install or some other magic trick?