https://www.activestate.com/resources/quick-reads/how-to-update-all-python-packages/

 

How to Update All Python Packages

The pip package manager can be used to update one or more packages system-wide. This guide shows how to update all Python packages for Windows and Linux.

www.activestate.com

1. Check that Python is installed

2. Get a list of all the outdated packages

pip list --outdated

3. Upgrade outdated packages

 

Update All Python Packages On Windows

1. Open a command shell by typing 'powershell' in the Search Box of the Task Bar

2. Enter:

pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade &_}

This will upgrade all packages system-wide to the latest version available in the Python Package Index (PyPI).

 

Update All Python Packages On Linux (Ubuntu)

To upgrade all packages using pip with grep:

pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip3 install -U

To upgrade all packages using pip with awk:

pip3 list -o | cut -f1 -d' ' | tr " " "\n" | awk '{if(NR>=3)print)' | cut -d' ' -f1 | xargs -n1 pip3 install -U

 

Updating Python Packages On Windows Or Linux

1. Output a list of installed packages into a requirements file (requirements.txt):

pip freeze > requirements.txt

2. Edit requirements.txt, and replace all '==' with '>='. Use the 'Replace All' command in the editor.

3. Upgrade all outdated packages:

pip install -r requirements.txt --upgrade

 

Updating All Packages In A Virtual Enviroment

The easiest way to update unpinned packages (i.e., packages that do not require a specific version) in a virtual environment is to run following Python script that makes use of pip:

import pkg_resources
from subprocess import call

for dist in pkg_resources.working_set:
    call("python -m pip install --upgrade " + dist.<projectname>, shell=True)

 

Updating All Packages In A Pipenv Environment

The simplest way to update all the unpinned packages in a specific virtual environment created with pipenv is to do the following steps:

1. Activate the Pipenv shell that contains the packages to be upgraded:

pipenv shell

2. Upgrade all packages:

pipenv update

'Python' 카테고리의 다른 글

설치된 패키지 목록 저장 및 복원  (0) 2022.08.25
Anaconda3  (0) 2021.08.16
Fibonacci series  (0) 2021.08.16
Array/List  (0) 2021.08.16
Number, String  (0) 2021.08.15

+ Recent posts