Home » Python

Python | How to upgrade all Python packages with pip?

Upgrading all Python packages with pip: Here, we are going to learn How to upgrade all Python packages with pip in Python?
Submitted by Sapna Deraje Radhakrishna, on January 10, 2020

While using Python as a programming language, it's a very common scenario to use a virtual environment and PIP, a package manager for python.

It's a common practice to use a text file, named as "requirement.txt", which would be populated with the list of libraries used in the given application.

Generally, the developers maintain the version of the libraries in the "requirement.txt", as shown in the below example,

    (venv) XXX:src XXX$ more requirements.txt 
    numpy==1.17.2
    requirements.txt (END)

Upgrading every library is a monotonous task, and hence the following commands can be used to upgrade all the packages in the venv (virtual environment) using PIP. We could either follow the below as a two-step process or also combine it to be a single line command.

Approach 1:

  1. Freeze all the libraries to a file called 'requirements.txt' (file name could be anything)
    pip freeze > installed_library_list.txt
    
  2. Update all the libraries available in the file
    pip install -r installed_library_list.txt –upgrade
    

Approach 2:

pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

The grep is to skip editable ("-e") package definitions, and the -n1 flag for xargs prevents stopping everything if updating one package fails.







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.