So I am trying to run a simple matplotlib example in my virtualenv (in the console). Here\'s the code:
import matplotlib
matplotlib.use(\'GTKAgg\')
import ma
pygtk cannot be installed in your virtualenv from PyPI, so
pip install pygtk
will download but not install. You can go through the hoops of downloading the tar files and compiling and installing those, but if it is OK to make links to the relevant packages installed in the system then activating your virtualenv and installing ruamel.venvgtk is enough:
pip install ruamel.venvgtk
This is a shameless plug for my own work, none of the other solutions here worked well with repeated virtualenv creation as is e.g. done by tox.
In the setup.py of the packages the following happens:
try:
import gtk
except ImportError:
print('--------------')
import subprocess
instdir = subprocess.check_output([
'/usr/bin/python',
'-c',
'import os, pygtk; print os.path.dirname(pygtk.__file__)',
]).strip()
for dst_base in sys.path:
if dst_base.strip():
break
for d in [
'pygtk.pth',
'pygtk.py',
'gtk-2.0',
'gobject',
'glib',
'cairo',
]:
src = os.path.join(instdir, d)
dst = os.path.join(dst_base, d)
if os.path.exists(src) and not os.path.exists(dst):
print('linking', d, 'to', dst_base)
os.symlink(src, dst)
i.e the system's python is asked where pygtk is installed (on Linux Mint 17.1 this is /usr/lib/python2.7/dist-packages), and then links are set up to the first path (that is non-zero length) for the activated python.