默认情况下是系统PIP而不是virtualenv PIP? [英] System PIP instead of virtualenv PIP by default?

查看:90
本文介绍了默认情况下是系统PIP而不是virtualenv PIP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将virtualenv与pip断断续续地使用了几天之后,我发现在virtualenv激活后使用的PIP版本是全局PIP,而不是相对于该环境的PIP.这样,如果您未设置外壳环境变量export PIP_RESPECT_VIRTUALENV=true,则pip会将任何新软件包(例如pip install argparse)安装到全局作用域,而不是仅安装到virtualenv.

After using virtualenv with pip off-and-on for a couple of days, I've found that the version of PIP that is used after the virtualenv is actived is the global PIP instead of the PIP relative to that environment; such that if you don't set the shell environment variable export PIP_RESPECT_VIRTUALENV=true, pip will install whatever new package (e.g. pip install argparse) to the global scope instead of only to the virtualenv.

如果激活了virtualenv,我希望PIP默认安装到virtualenv.

I would expect PIP to install to the virtualenv by default, if that virtualenv is activated.

默认情况下,以这种方式工作吗?

Is there a reasoning behind it not working that way by default?

请参见说明此处有关PIP_RESPECT_VIRTUALENV的方式有效.

See explanation here for how PIP_RESPECT_VIRTUALENV works.

推荐答案

创建virtualenv时,activate文件 hardcodes 变量VIRTUAL_ENV到您第一次创建该文件的位置.根目录.然后,当您source <your-venv>/bin/activate导出该变量.

When you create a virtualenv, the activate file hardcodes the variable VIRTUAL_ENV to the location in which you first created the root directory. This variable is then exported when you source <your-venv>/bin/activate.

因此,如果在创建virtualenv目录之后移动了virtualenv目录,则硬编码的文件路径将不正确.

Consequently, if you move the virtualenv directory subsequent to its creation, the hardcoded file path will be incorrect.

只需在文本编辑器中打开<your-venv>/bin/activate并确保将VIRTUAL_ENV设置为您的virtualenv目录的新路径:

Just open <your-venv>/bin/activate in a text editor and make sure VIRTUAL_ENV is set to the new path of your virtualenv directory:

VIRTUAL_ENV="/Full/path/to/<your-venv>"
export VIRTUAL_ENV

再次运行source <your-venv>/bin/activate之前.

然后,您当然可以使用which pip测试pip的版本,该版本会产生:

Then of course you can test the version of pip with which pip which should produce:

/Full/path/to/<your-venv>/bin/pip

而不是/usr/bin/pip/bin/pip

这篇关于默认情况下是系统PIP而不是virtualenv PIP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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