Upgrading all packages with pip

2019-01-02 19:07发布

Is it possible to upgrade all Python packages at one time with pip?

Note that there is a feature request for this on the official issue tracker.

标签: python pip
30条回答
后来的你喜欢了谁
2楼-- · 2019-01-02 19:18

use awk update packges: pip install -U $(pip freeze | awk -F'[=]' '{print $1}')

windows powershell update foreach($p in $(pip freeze)){ pip install -U $p.Split("=")[0]}

查看更多
初与友歌
3楼-- · 2019-01-02 19:18

one line in powershell 5.1 with adm rights, python 3.6.5 and pip ver 10.0.1:

pip list -o --format json | ConvertFrom-Json | foreach {pip install $_.name -U --no-warn-script-location}

it works smoothly if there are no broken packages or special wheels in the list...

查看更多
妖精总统
4楼-- · 2019-01-02 19:19

I had the same problem with upgrading. Thing is, i never upgrade all packages. I upgrade only what i need, because project may break.

Because there was no easy way for upgrading package by package, and updating the requirements.txt file, i wrote this pip-upgrader which also updates the versions in your requirements.txt file for the packages chosen (or all packages).

Installation

pip install pip-upgrader

Usage

Activate your virtualenv (important, because it will also install the new versions of upgraded packages in current virtualenv).

cd into your project directory, then run:

pip-upgrade

Advanced usage

If the requirements are placed in a non-standard location, send them as arguments:

pip-upgrade path/to/requirements.txt

If you already know what package you want to upgrade, simply send them as arguments:

pip-upgrade -p django -p celery -p dateutil

If you need to upgrade to pre-release / post-release version, add --prerelease argument to your command.

Full disclosure: I wrote this package.

查看更多
零度萤火
5楼-- · 2019-01-02 19:20

The following one-liner might prove of help:

pip list --format freeze --outdated | sed 's/(.*//g' | xargs -n1 pip install -U

xargs -n1 keeps going if an error occurs.

If you need more "fine grained" control over what is omitted and what raises an error you should not add the -n1 flag and explicitly define the errors to ignore, by "piping" the following line for each separate error:

| sed 's/^<First characters of the error>.*//'

Here is a working example:

pip list --format freeze --outdated | sed 's/(.*//g' | sed 's/^<First characters of the first error>.*//' | sed 's/^<First characters of the second error>.*//' | xargs pip install -U
查看更多
与风俱净
6楼-- · 2019-01-02 19:21

My script:

pip list --outdated --format=legacy | cut -d ' ' -f1 | xargs -n1 pip install --upgrade
查看更多
只靠听说
7楼-- · 2019-01-02 19:23

You can use the following Python code. Unlike pip freeze, this will not print warnings and FIXME errors. For pip < 10.0.1

import pip
from subprocess import call

packages = [dist.project_name for dist in pip.get_installed_distributions()]
call("pip install --upgrade " + ' '.join(packages), shell=True)

For pip >= 10.0.1

import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
call("pip install --upgrade " + ' '.join(packages), shell=True)
查看更多
登录 后发表回答