如果站点包更新超出我在 virtualenv 中使用 pip 指定的版本,会发生什么情况?
假设我的 virtualenv 安装不使用--no-site-packages
。我运行 bin/pip install somepackage==1.0.0
,但它已经存在于我的 site-packages
中,因此未安装。随后,安装的 site-packages
副本更新为 somepackage==2.0.0
。
我的 virtualenv 中会发生什么?它会使用版本 2,还是自己下载版本 1?
Assume I have a virtualenv installation that does not use --no-site-packages
. I run bin/pip install somepackage==1.0.0
, but it's already present in my site-packages
so it's not installed. Later, the copy installed site-packages
is updated to somepackage==2.0.0
.
What will happen in my virtualenv? Will it use the version 2, or download version 1 for itself?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于。如果导入
somepackage
的包均未使用setuptools
API,则其工作方式如上所述。如果您的 virtualenv 中的任何软件包使用setuptools
(或Distribute
)来指定somepackage
的特定版本要求,setuptools
将搜索满足要求的somepackage
版本。如果在安装时找不到合适的安装版本,它将在外部搜索并尝试安装。如果在运行时找不到,程序就会失败并出现异常。例如,如果
somepackage 1.0.0
已安装在系统站点包中,则一切正常。如果您随后使用pip
将系统站点包更新为somepackage 2.0.0
(这会卸载旧版本),则该脚本将在运行时失败并显示:如果您安装了这两个版本使用
easy_install
而不是pip
的somepackage
,情况通常会有所不同。默认情况下,easy_install
不会卸载软件包,并且支持多个版本的软件包(多版本eggs)。因此,somepackage
的两个版本都可以在系统站点包中使用,并且脚本不会失败。setuptools
(以及它的Distribute
克隆)必须跳过许多环节才能使多版本支持合理地工作。许多开发人员对所有这些额外的复杂性感到不满,并认为使用单独的virutalenv
来支持多个版本的包会更容易、更透明,为此,使用更简单的 pip 模型代码> 更合适。 (公平地说,setuptools
,virtualenv
后来才出现。)It depends. If none of the packages that are importing
somepackage
use thesetuptools
API, then it works as described above. If any packages in your virtualenv usesetuptools
(orDistribute
) to specify specific version requirements forsomepackage
,setuptools
will search for a version ofsomepackage
that meets the requirements. If it can't find a suitable installed version at install time, it will search externally and attempt to install it. If it can't find one at runtime, the program fails with an exception.For example, if
somepackage 1.0.0
was already installed in the system site-packages, everything is fine. If you then update the system site-packages tosomepackage 2.0.0
withpip
, which uninstalls the old version, the script will fail at runtime with:If you installed both versions of
somepackage
witheasy_install
instead ofpip
, things would normally be different. By default,easy_install
does not uninstall packages and it supports multiple versions of packages (multi-version eggs). So both versions ofsomepackage
would be available in the system site-packages and the script would not fail.setuptools
(and theDistribute
clone of it) has to jump through many hoops to make the multiple version support work reasonably. Many developers frown on all that extra complexity and argue that it is easier and more transparent to support multiple versions of packages with separatevirutalenv
's and, for that, the simpler model ofpip
is more appropriate. (In fairness tosetuptools
,virtualenv
came along later.)仅使用在 sys.path 中找到的具有给定名称的第一个包/模块。如果您的 venv 早于系统目录,则将使用您的 venv。
Only the first package/module found in
sys.path
with the given name will be used. If your venv is earlier than the system directory then your venv will be used.