Updating Your Pip Requirements File

November 9, 2018

While revisiting an old Python project you may come to realize that your requirements.txt file contains out of date versions. You could go through and research each library and get it's latest version number but may be discouraged if there too many.

The following is a technique to update the entire file without having to take too much time.

This technique is good if your goal to to update each library to it's most recent first.

Step 1 Change the == to >= for each entry

This will unpin the reference to a specific version

Old requirements.txt

amqp==1.4.9
anyjson==0.3.3
BeautifulSoup==3.2.1
billiard==3.3.0.23
celery==3.1.13
certifi==2018.1.18
chardet==3.0.4
Django==1.6.6
django-extensions==1.3.11
django-celery==3.1.1
idna==2.6
kombu==3.0.37
pytz==2018.3
requests==2.18.4
six==1.7.3
urllib3==1.22
vine==1.1.4

Edited requirements.txt

amqp>=1.4.9
anyjson>=0.3.3
BeautifulSoup>=3.2.1
billiard>=3.3.0.23
celery>=3.1.13
certifi>=2018.1.18
chardet>=3.0.4
Django>=1.6.6
django-extensions>=1.3.11
django-celery>=3.1.1
idna>=2.6
kombu>=3.0.37
pytz>=2018.3
requests>=2.18.4
six>=1.7.3
urllib3>=1.22
vine>=1.1.4

Step 2 Run pip with the upgrade flag

$ pip install -r requirements.txt --upgrade

Step 3 Verify the new requirements

$ pip list

Step 4 Create a new requirements.txt file

$ pip freeze > requirements.txt


Tags: pip python