[英]Pip install requirements.txt in venv: How to ignore system site packages of different version?
I am in a virtual environment which shares the system site packages (created with venv
in Python 3.5), and I would like to install all packages in a given requirements.txt into this venv.我在共享系统站点包(在 Python 3.5 中使用
venv
创建)的虚拟环境中,我想将给定 requirements.txt 中的所有包安装到这个 venv 中。 The system-wide python installation is read-only, so I cannot modify it.系统范围的python安装是只读的,所以我不能修改它。
Now, for example, my requirements.txt lists, among many others,现在,例如,我的 requirements.txt 列出了许多其他内容,
SomePackage==2.0
as requirement, while the system installation already contains SomePackage-1.0
.根据要求,而系统安装已经包含
SomePackage-1.0
。 Pip thus tries to uninstall SomePackage-1.0
to upgrade to version 2.0. Pip 因此尝试卸载
SomePackage-1.0
以升级到版本 2.0。 This, however, fails because the system-wide python installation is read-only.但是,这会失败,因为系统范围的 python 安装是只读的。
Is there a way to run pip install -r requirements.txt
in a way that ignores installed packages if they have a different version from the required one and just installs the required version into the venv?有没有办法运行
pip install -r requirements.txt
以忽略已安装的软件包,如果它们的版本与所需的版本不同,而只是将所需的版本安装到 venv 中?
I guess this would be similar to installing each package one by one and using --ignore-installed
whenever the package is already present in a different version than the required one.我想这类似于一个一个地安装每个包并在包已经存在于与所需版本不同的版本中时使用
--ignore-installed
。 This, however, seems quite cumbersome.然而,这似乎相当麻烦。 Is there a better way?
有没有更好的办法?
Note that I am using a venv with shared system site packages because I want to avoid the installation of several huge packages each time I create a new venv.请注意,我将 venv 与共享系统站点包一起使用,因为我想避免每次创建新 venv 时都安装几个巨大的包。 Thus I do not want to switch to a fully isolated venv, which would, of course, not have the above issue.
因此,我不想切换到完全隔离的 venv,这当然不会有上述问题。
Any hint would be greatly appreciated!任何提示将不胜感激! Thanks a lot!
非常感谢!
To list only the packages you need for your project inside venv, and not all global packages from your computer, first you have to activate the virtualenv, and from (env) to run pip freeze > requirements.txt
command.要仅列出 venv 中项目所需的包,而不是计算机中的所有全局包,首先必须激活 virtualenv,然后从 (env)运行
pip freeze > requirements.txt
命令。
So you will have strictly listed the packages you need for the specified project.因此,您将严格列出指定项目所需的包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.