Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: virtualenv - gtk-2.0

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

like image 406
Pickels Avatar asked Aug 27 '10 00:08

Pickels


3 Answers

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)

Update

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

like image 170
kwatford Avatar answered Nov 09 '22 18:11

kwatford


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/
like image 6
t00m Avatar answered Nov 09 '22 19:11

t00m


Remember to add a link to pygtk.py

ln -s /usr/lib/python2.7/dist-packages/pygtk.py lib/python2.7/dist-packages/
like image 1
salomonvh Avatar answered Nov 09 '22 20:11

salomonvh