是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
是否可以使用pip一次性升级所有Python包?
注意:官方问题跟踪器上对此有一个功能请求。
当前回答
在蝙蝠脚本中
call pip freeze > requirements.txt
call powershell "(Get-Content requirements.txt) | ForEach-Object { $_ -replace '==', '>=' } | Set-Content requirements.txt"
call pip install -r requirements.txt --upgrade
其他回答
在Windows或Linux上更新Python包
1-将已安装软件包的列表输出到需求文件(requirements.txt)中:
pip freeze > requirements.txt
2-编辑requirements.txt,并将所有“==”替换为“>=”。在编辑器中使用“全部替换”命令。
3-升级所有过时的软件包
pip install -r requirements.txt --upgrade
资料来源:https://www.activestate.com/resources/quick-reads/how-to-update-all-python-packages/
cmd中的一行:
for /F "delims= " %i in ('pip list --outdated --format=legacy') do pip install -U %i
因此
管道检查
之后应该确保没有中断依赖关系。
拉玛纳回答的一个线性版本。
python -c 'import pip, subprocess; [subprocess.call("pip install -U " + d.project_name, shell=1) for d in pip.get_installed_distributions()]'
没有必要这么麻烦或安装一些软件包。
在Linux shell上更新pip包:
pip list --outdated --format=freeze | awk -F"==" '{print $1}' | xargs -i pip install -U {}
在Windows powershell上更新pip包:
pip list --outdated --format=freeze | ForEach { pip install -U $_.split("==")[0] }
一些要点:
将pip作为python版本替换为pip3或pip2。pip-list——过时,用于检查过时的pip包。--我的pip版本22.0.3的格式只有3种类型:列(默认)、冻结或json。冻结是命令管道中更好的选项。尽可能多地保持命令简单和可用。
查看所有过时的软件包
pip list --outdated --format=columns
安装
sudo pip install pipdate
然后键入
sudo -H pipdate