使用 pip 命令从 requirements.txt 升级 python 包 [英] Upgrade python packages from requirements.txt using pip command

查看:68
本文介绍了使用 pip 命令从 requirements.txt 升级 python 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 pip 命令从 requirements.txt 文件升级我所有的 python 包?

How do I upgrade all my python packages from requirements.txt file using pip command?

尝试使用以下命令

$ pip install --upgrade -r requirements.txt

因为,python 包以版本号 (Django==1.5.1) 为后缀,它们似乎没有升级.有没有比手动编辑 requirements.txt 文件更好的方法?

Since, the python packages are suffixed with the version number (Django==1.5.1) they don't seem to upgrade. Is there any better approach than manually editing requirements.txt file?

编辑

正如安迪在他的回答中提到的那样,软件包被固定到特定版本,因此无法通过 pip 命令升级软件包.

As Andy mentioned in his answer packages are pinned to a specific version, hence it is not possible to upgrade packages through pip command.

但是,我们可以使用以下命令通过 pip-tools 实现这一点.

But, we can achieve this with pip-tools using the following command.

$ pip-review --auto

这将自动从 requirements.txt 升级所有包(确保使用 pip install 命令安装 pip-tools).

this will automatically upgrade all packages from requirements.txt (make sure to install pip-tools using pip install command).

推荐答案

没有.您的需求文件已固定到特定版本.如果您的要求设置为该版本,则不应尝试升级到这些版本之外.如果您需要升级,则需要在需求文件中切换到未固定版本.

No. Your requirements file has been pinned to specific versions. If your requirements are set to that version, you should not be trying to upgrade beyond those versions. If you need to upgrade, then you need to switch to unpinned versions in your requirements file.

示例:

lxml>=2.2.0

这会将 lxml 升级到任何比 2.2.0 新的版本

This would upgrade lxml to any version newer than 2.2.0

lxml>=2.2.0,<2.3.0

这会将 lxml 升级到 2.2.0 和 2.3.0 之间的最新版本.

This would upgrade lxml to the most recent version between 2.2.0 and 2.3.0.

这篇关于使用 pip 命令从 requirements.txt 升级 python 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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