Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrading pip packages after python upgrade

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.

like image 861
MaxRussell Avatar asked Oct 16 '18 09:10

MaxRussell


People also ask

Does upgrading pip upgrade Python?

Many users question exactly just how to upgrade to the latest version of PIP, given the ever-evolving and fast-moving python ecosystem. The short answer is, pip is just like any other PyPI package and you can upgrade it to newer (or downgrade to older) versions, just as you would upgrade or downgrade any other package.

How do I upgrade a Python package to a specific version?

How do I Install a Specific Version of a Python Package? To install a specific version of a Python package you can use pip: pip install YourPackage==YourVersion . For example, if you want to install an older version of Pandas you can do as follows: pip install pandas==1.1. 3 .

How do I upgrade Python to a pip version?

Install a specific version of Python packages General syntax to install the specific version of Python packages is pip install <python_package_name>==<version> . If you don't specify the version, the latest version of the Python package will be installed.

Should I upgrade my pip version?

New software releases can bring bug fixes, new features, and faster performance. For example, NumPy 1.20 added type annotations, and improved performance by using SIMD when possible. If you're installing NumPy, you might want to install the newest version.


2 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
like image 160
Girish Vas Avatar answered Nov 05 '22 06:11

Girish Vas


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.

like image 38
Treedbox Avatar answered Nov 05 '22 08:11

Treedbox