Virtualenv on Ubuntu without site packages

I have been using virtualenv lately while developing in python. I like the idea of ​​an isolated development environment using the -no-site-packages option, but this can be a bit complicated when developing a PyGTK application. PyGTK modules are installed on Ubuntu by default, and I would like to make virtualenv (with --no-site packages) information about specific modules that are located elsewhere on the system.

What is the best way to do this? Or should I just suck it and refuse the -no-site-packages option?

+24
python ubuntu virtualenv pygtk
Oct 30 '08 at 4:32
source share
5 answers
$ 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/ $ ln -s /usr/lib/pymodules/python2.6/pygtk.pth $ ln -s /usr/lib/pymodules/python2.6/pygtk.py $ ln -s /usr/lib/pymodules/python2.6/cairo/ $ python >>> import pygtk >>> import gtk 
+34
Nov 03 '09 at 22:20
source share

One way is to add paths to your code using sys.path.

 import sys sys.path.append(somepath) 

Another way is to use a site that processes .pth files in addition to adding to sys.path.

 import site site.addsitedir(sitedir, known_paths=None) 

https://docs.python.org/library/site.html

But you probably don't want to add this to all of your linked code.

I saw a mention of the sitecustomize.py file used to do something similar, but after some testing, I couldn’t get it to work as you would expect.

It is mentioned here that sitecustomize.py auto-import ended in 2.5, if your not on 2.5 try. (just add one of the methods to add the path to the file and place it in the directory in which your program is launched) The method of operation is described in the message for users of size 2.5 and above.

http://code.activestate.com/recipes/552729/

+4
Oct 30 '08 at 5:22
source share

In this situation, I find that symbolic links or even copying certain files (packages, modules, extensions) work very well.

This allows the program to emulate the launch in the target environment, rather than changing the application in accordance with the development environment.

The same goes for AppEngine.

+1
Oct 30 '08 at 9:57
source share

Take a look at the postmkvirtualenv hook script here:

stack overflow

In this case, it uses it to import PyQt and SIP after creating a new Virtualenv, but you can add the packages you need for LIBS.

And vote for the script, because it's fantastic :)

+1
Aug 26 2018-12-12T00:
source share

If you want to include links in the corresponding python gtk-2.0 system in virtualenv, you can simply use pip to install ruamel.venvgtk :

pip install ruamel.venvgtk You do not have anything to import, links are set during installation.

This is especially convenient if you use tox , in which case you only need to include the dependency (for tox):

 deps: pytest ruamel.venvgtk 

and the new python2.7 environment setting will have the corresponding links included before running the tests.

More information on link customization can be found in this answer.

0
Dec 14 '14 at 16:38
source share



All Articles