6

After upgrading from Python 3.6 to 3.7 (Windows), what is the correct method to upgrade all existing packages installed with Pip in the previous version? This is not using virtualenv or pipenv.

4

3 Answers 3

3

You can try the following script to upgrade all the installed packages.

pip list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U
Sign up to request clarification or add additional context in comments.

1 Comment

Source. Note that this just upgrades all installed packages for the current Python version. If you just upgraded Python, there will be zero packages.
1

I used a variation of upgrading all pip packages without Python upgrade using two different versions of pip (and for my user packages):

pip3.6 list --user --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3.7 install --user --upgrade

pip3.6 will list the packages that are installed for Python 3.6, and pip3.7 will install the packages from that list for Python 3.7. Leave out the --user flag (twice) if you don't have user packages.

Comments

0

You can upgrade all outdated packages directly:

pip install -U $(pip list -o freeze | cut -f1 -d=)

Long version:

pip install --upgrade $(pip list --outdated --format freeze | cut --fields=1 --delimiter="=")

Or you can create and use a file to list all outdated pip packages names:

list all outdated pip packages and format the output as "freeze";

-d= cut everything after "=" (delimiter);

> dump the result to a file.

pip list -o freeze | cut -f1 -d= > pip_list_outdated.txt

Long version:

pip list --outdated --format freeze | cut --fields=1 --delimiter="="> pip_list_outdated.txt

The output will be something like:

gunicorn
PySimpleGUI
python-engineio
python-socketio
requests
setuptools
six

Upgrade to latest version outdated pip packages using the name in each line:

pip install -U $(<pip_list_outdated.txt)

Long version:

pip install --upgrade $(<pip_list_outdated.txt)

Wrong way:

If you type:

pip list -o freeze:

You will get something like:

autopep8==1.4.3
chardet==3.0.4
Django==2.1.4

And if you try to upgrade using this result:

pip install -U $(pip list -o freeze)

You will get the messages:

Requirement already up-to-date: autopep8==1.4.3 in ...
Requirement already up-to-date: chardet==3.0.4 in ...
Requirement already up-to-date: Django==2.1.4 in ...

It happens because the version listed in the result is already installed.

To upgrade to the latest version, you need the package name without the version or the name with the version number you want to upgrade.

1 Comment

This is what I get when trying to run it: Usage: pip install [options] <requirement specifier> [package-index-options] ... pip install [options] -r <requirements file> [package-index-options] ... pip install [options] [-e] <vcs project url> ... pip install [options] [-e] <local project path> ... pip install [options] <archive url/path> ... no such option: --------------------------

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.