Including global package into a virtualenv that has been created with --no-site-packages

心已入冬 提交于 2019-11-30 06:41:22

If you're using virtualenvwrapper and you might be able to use the postmkvirtualenv script to automatically create symlinks in the new virtualenv sitepackages directory.

#!/bin/sh
cdsitepackages
ln -s /path/to/system/site-packages/package-name
cdvirtualenv

If you are using virtualenvwrapper, the shell command add2virtualenv should be present in an active virtualenv. Use:

add2virtualenv /path/to/package

to add an entry to the PTH file _virtualenv_path_extensions.pth in your virtualenv site-packages.

The benefit of using add2virtualenv rather than creating symlinks yourself, is that you can remove the package from being importable by commenting out its line in the PTH file. This makes it easier to check your code's validity against several versions of a library on which it depends.

I haven't actually tried this with those specific packages, but I would guess that a simple symlink from the global site-packages into the virtualenv's site-packages might work, and this is easily scriptable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!