对virtualenv使用单个站点包(作为例外) [英] Use a single site package (as exception) for a virtualenv

查看:110
本文介绍了对virtualenv使用单个站点包(作为例外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在virtualenv中,如何忽略单个软件包的no-site-packages规则?

In a virtualenv, how can I ignore the no-site-packages rule for a single package?

一些背景:我在部署中使用virtualenv,但是由于我一直使用lxml,因此部署时间要长得多.每次重新安装新的virtualenv时,编译此过程最多需要15分钟.我可以为lxml设置某种例外并使用全局站点包吗?除了将其复制到新的virtualenv中,还有其他更安全/可靠的选择吗?

Some background: I use virtualenv for my deployments, but these take a lot longer since I have been using lxml. Compiling this takes up to 15 minutes each time I reinstall for a new virtualenv. Can I make some sort of an exception for lxml and use the global site package? Is there any safer/more reliable option than just copying it into the new virtualenv?

推荐答案

简短的回答:不,但是您可以做其他事情来解决相同的问题.

Short answer: no, but you can do something else to solve the same problem.

--no-site-packages选项(除非您指定--system-site-packages,现在是默认选项)控制是否将某些目录添加到

The --no-site-packages option (which is now the default unless you specify --system-site-packages) controls whether or not some directories are added to sys.path. A given directory is either in or not, you can not discriminate only one package in that directory.

但是,您可以在虚拟环境的site-packages目录中建立指向软件包的符号链接.在我的系统上:

However, you can make a symbolic link to the package in the virtual environment’s site-packages directory. On my system:

ln -s /usr/lib/python2.7/site-packages/lxml ./env/lib/python2.7/site-packages

或更笼统(使用系统的python,而不是环境的python):

Or more generically (using the system’s python, not the environment’s):

ln -s $(python -c 'import lxml, os.path; print(os.path.dirname(lxml.__file__)') ./env/lib/python2.7/site-packages

如果您使用的系统不支持符号链接,那么在更新系统范围的lxml时,复制也应该可以进行,但复制起来会更脆弱.

If you’re on a system that does not support symbolic links, copying should also work but is more fragile when the system-wide lxml is updated.

这篇关于对virtualenv使用单个站点包(作为例外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆