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.
3 Answers
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
1 Comment
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
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.
pip freeze > old_reqs.txtfrom Python3.6 and thenpip install -r old_reqs.txt --upgradein Python3.7.