To add gtk-2.0 to my virtualenv I did the following:
$ virtualenv --no-site-packages --python=/usr/bin/python2.6 myvirtualenv
$ cd myvirtualenv
$ source bin/activate
$ cd lib/python2.6/
$ ln -s /usr/lib/pymodules/python2.6/gtk-2.0/
Virtualenv on Ubuntu with no site-packages
Now in the Python interpreter when I do import gtk it says: No module named gtk. When I start the interpreter with sudo it works.
Any reason why I need to use sudo and is there a way to prevent it?
Update:
Forgot to mention that cairo and pygtk work but it's not the one I need.
Update2:
Here the directory to show that I ain't crazy.
http://www.friendly-stranger.com/pictures/symlink.jpg
sudo python
imports it just fine because that interpreter isn't using your virtual environment. So don't do that.
You only linked in one of the necessary items. Do the others mentioned in the answer to the question you linked as well.
(The pygtk.pth file is of particular importance, since it tells python to actually put that directory you linked onto the python path)
Put that stuff in $VIRTUALENV/lib/python2.6/site-packages/ rather than the directory above that.
Looks like the .pth files aren't read from that directory - just from site-packages
This works for me (Ubuntu 11.10):
once you activate your virtualenv directory make sure 'dist-packages' exists:
mkdir -p lib/python2.7/dist-packages/
Then, make links:
For GTK2:
ln -s /usr/lib/python2.7/dist-packages/glib/ lib/python2.7/dist-packages/
ln -s /usr/lib/python2.7/dist-packages/gobject/ lib/python2.7/dist-packages/
ln -s /usr/lib/python2.7/dist-packages/gtk-2.0* lib/python2.7/dist-packages/
ln -s /usr/lib/python2.7/dist-packages/pygtk.pth lib/python2.7/dist-packages/
ln -s /usr/lib/python2.7/dist-packages/cairo lib/python2.7/dist-packages/
For GTK3:
ln -s /usr/lib/python2.7/dist-packages/gi lib/python2.7/dist-packages/
Remember to add a link to pygtk.py
ln -s /usr/lib/python2.7/dist-packages/pygtk.py lib/python2.7/dist-packages/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With