简体   繁体   English

venv中的pip install requirements.txt:如何忽略不同版本的系统站点包?

[英]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.

相关问题 使用requirements.txt安装python软件包 - Install python packages with requirements.txt pip 安装在 EC2 上的 virtualenv 中,安装时 requirements.txt 文件中缺少包 - pip install in virtualenv on EC2 missing packages in requirements.txt file on install 在Python中,`pip -r requirements.txt`不会递归地安装包*? - In Python, `pip -r requirements.txt` doesn't install packages *recursively*? 是否可以使用 pip freeze 从 requirements.txt 中排除 IDE 包? - Is it possible to exclude IDE packages from requirements.txt with pip freeze? Pip 安装 -r requirements.txt 没有失败 - Pip Install -r requirements.txt Without Failing “-r”在 pip install -r requirements.txt 中有什么作用 - What does " -r " do in pip install -r requirements.txt 如何查找为pip或conda列表中未显示的requirements.txt安装的库的版本? - How to find version of libraries installed for requirements.txt that don't show in pip or conda list? 如何从 requirements.txt 在 Google Cloud Functions 中安装最新的库版本 - How to install newest library version in Google Cloud Functions from requirements.txt 在 requirements.txt 中强制重新安装 pip - pip force reinstall in requirements.txt 来自 GitHub 源的 pip install 无法安装存储库的 requirements.txt 中定义的依赖项 - pip install from GitHub source fails to install dependencies defined in repository's requirements.txt
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM