8

I want to use the default (no site packages) of virtualenv.

But some modules are difficult to install in a virtualenv (for example gtk). With "difficult" I mean that you need to have a lot of c-header files installed and a lot of stuff needs to be compiled.

I know that I can solve this by not installing these packages with pip, but to create symlinks to make some modules available from the global site-packages directory.

But is this the right direction?

Is there a way to create the symlinks with pip or virtualenv?

Update

In 2013 I wanted some modules like psycopg2, gtk, python-ldap and other which are installed on my linux server via rpm/dpkg in the virtualenv.

The symlinking or other work-arounds did make things more complicated, not simpler. We use this option today (2017)

--system-site-packages

Give the virtual environment access to the global site-packages.

guettli
  • 25,042
  • 81
  • 346
  • 663
  • What do you meand by `hard to install in a virtualenv`, what is *hard*? Symlinks are ok, though, see http://stackoverflow.com/a/3399920/1265154 for a way of an automation of process – alko Dec 03 '13 at 08:00
  • @alko thank you for asking. I updated the question: It is hard/difficult since you need a lot of c-header files and a lot needs to be compiled if you install with pip (for packages like gtk or matplotlib). – guettli Dec 03 '13 at 08:30

2 Answers2

0

I'd say yeah, that's the right direction.

Your questions sounds similar to something I dealt with: installing OpenCV into virtualenv. My problem was that OpenCV wasn't available via pip (Python Package Index). What I ended up doing was querying the system-wide global Python installation for the module in question, and then copy-ing the .so into my virtualenv.

The whole process, including the boilerplate Makefile I used, are captured here: https://stackoverflow.com/a/19213369/1510289

You could do something similar by sym-linking instead of copying. The reason I ended up copying the library was because I use Make, and Make doesn't handle dependencies for symbolic links in a way I needed (as explained in the URL above.)

Hope this helps...

Community
  • 1
  • 1
Velimir Mlaker
  • 10,664
  • 4
  • 46
  • 58
0

How are you compiling each of these 'hard' packages from scratch? Are you doing something like:

python setup.py install

If so, replace that with:

python setup.py bdist_wheel

Then look in the ./dist directory for a .whl file. Then take whatever that file is, and do (after activating the environment)

pip install `./dist/whateverTheFileIsCalled.whl`
falsePockets
  • 3,826
  • 4
  • 18
  • 37