6

I want to create a virtualenv without global python packages, but with the scipy distribution that is shared; installing scipy takes quite a while and I don't want to go through the motions too often.

So I run add2virtualenv /Library/Python/2.7/site-packages/scipy and after running add2virtualenv it shows the directory is added. (I doublechecked, it is the right directory). Then I issue workon myfile to be sure the working directories are reloaded. However, when I try to load scipy, it is an ImportError: No module named scipy. This is unexpected.

Has anyone used a global scipy in a non-global-sitepackages virtualenv?

Okke
  • 891
  • 10
  • 13
  • 1
    add2virtualenv add the specified directory to PYTHONPATH. You should therefore add your entire site-package to import scipy. – rubik May 09 '12 at 15:12
  • 1
    An alternative solution should be symlinking scipy directory inside virtual env's site-package – rubik May 09 '12 at 15:12
  • Thank you. So I misinterpreted the way add2virtualenv should be used. Is there no command that makes it easy to add a specific package? (other than symlinking?) – Okke May 09 '12 at 15:33
  • I don't know how virtualenvwrapper works, but I don't think so... Symlinking to me seems a good solution. After all, many modules inside virtualenv's site-package are symlinked. – rubik May 09 '12 at 15:40
  • what I typically do is create one 'base' virtualenv with `--no-system-site-packages`, pip install scipy, numpy etc. in it, then use `cpvirtualenv` to clone it whenever I want a new 'throwaway' virtualenv to mess around with. – ali_m Jul 17 '13 at 23:40

1 Answers1

3

So, to summarize, the actual problem here is that the directory including the packages to be imported must be used, instead of the specific package. That is, instead of

add2virtualenv /Library/Python/2.7/site-packages/scipy

It should be

add2virtualenv /Library/Python/2.7/site-packages

Beware: this solution has the drawback that you do not only include scipy, but any other packages in /Library/Python/2.7/site-packages.


An alternate, space-efficent solution could be symlinking scipy directory inside the virtual env's site-package. This can be done, in your virtual env, through:

cdsitepackages
ln -s /Library/Python/2.7/site-packages/scipy scipy

All credits go to @rubik (see the comments)

Check out this answer to find your site-packages path in case it is different than the one used here.

Community
  • 1
  • 1
bernard paulus
  • 1,644
  • 1
  • 21
  • 33