I already answered this question here. Here's my solution:

Because there was no easy way for upgrading package by package, and updating the requirements.txt file, I wrote this pip-upgrader which also updates the versions in your requirements.txt file for the packages chosen (or all packages).

Installation

Copypip install pip-upgrader

Usage

Activate your virtualenv (important, because it will also install the new versions of upgraded packages in current virtualenv).

cd into your project directory, then run:

Copypip-upgrade

Advanced usage

If the requirements are placed in a non-standard location, send them as arguments:

Copypip-upgrade path/to/requirements.txt

If you already know what package you want to upgrade, simply send them as arguments:

Copypip-upgrade -p django -p celery -p dateutil

If you need to upgrade to pre-release / post-release version, add --prerelease argument to your command.

Full disclosure: I wrote this package.

Answer from Simion Agavriloaei on Stack Overflow
🌐
Medium
medium.com › @python-javascript-php-html-css › effortlessly-upgrade-all-python-packages-using-pip-1b9e720a6be0
Upgrade All Python Packages Effortlessly With pip
August 24, 2024 - Is there a way to upgrade all packages listed in a requirements file? Yes, you can use pip install -r requirements.txt — upgrade to upgrade all packages listed in the file.
Discussions

How to upgrade all Python packages with pip - Stack Overflow
Upgrades pip to latest version. Upgrades all outdated packages. For each packages being upgraded checks requirements.txt for any version specifiers. More on stackoverflow.com
🌐 stackoverflow.com
how do you upgrade all outdated pip packages?
This should work: pip freeze > requirements.txt And then: pip install -r requirements.txt --upgrade More on reddit.com
🌐 r/learnpython
8
2
March 22, 2019
python - How can I upgrade specific packages using pip and a requirements file? - Stack Overflow
Please check @dr-jimbob 's answer because recent versions of pip will actually upgrade all other dependencies that the package you are upgrading depends on. ... In an app that has a Django backend and Angular frontend, should the requirements.txt file be in the root directory (and run there ... More on stackoverflow.com
🌐 stackoverflow.com
How to keep your requirements.txt updated
Just run a pip freeze > requirements.txt (google this to be sure, it could be reversed <) while your local venv is running and it'll output that file at your current directory. More on reddit.com
🌐 r/djangolearning
11
10
January 15, 2023
🌐
Better Stack
betterstack.com › community › questions › how-to-upgrade-all-python-packages-with-pip
How to upgrade all Python packages with pip? | Better Stack Community
Alternatively, you can use the pip freeze command to generate a requirements file that lists all the packages in your environment, and then use the pip install -r command to upgrade all the packages at once:
🌐
PythonHow
pythonhow.com › how › upgrade-all-python-packages-with-pip
Here is how to upgrade all Python packages with pip in Python
# first, use the pip freeze command to generate a list of installed packages pip freeze > requirements.txt # next, use the pip install command to upgrade all the packages in the list pip install -r requirements.txt --upgrade
🌐
GitHub
gist.github.com › hritik5102 › 35b2886771d60fc6d7a95b6fd55c62ba
How To Update All Python Packages · GitHub
Open a command shell by typing ‘powershell’ in the Search Box of the Task bar Update All Python Packages On Windows · $ pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_} ... Edit requirements.txt, and replace all ‘==’ ...
Find elsewhere
🌐
GitHub
gist.github.com › marius-test › 1081d6ee29158a26d8c5983f6901012e
PIP Upgrade All Packages · GitHub
Open the requirements.txt file in Notepad and replace all == with >= using the CTRL+H shortcut and then the Replace all button. Then, execute the following command in the Terminal to upgrade all packages:
🌐
GitHub
gist.github.com › dl6nm › 1bd40ed663be228f54a28aec35cf616b
Hot to update all Python packages with pip · GitHub
$ pip3 install --upgrade $(pip3 list --outdated --format=json | jq -r '.[].name') If nothing can be upgraded, the command will fail with the following · ERROR: You must give at least one requirement to install (see "pip help install")
🌐
GitHub
github.com › alanhamlett › pip-update-requirements
GitHub - alanhamlett/pip-update-requirements: Update the packages in a requirements.txt file. · GitHub
Update the packages in a requirements.txt file. ... Give pur your requirements.txt file and it updates all your packages to the latest versions.
Starred by 643 users
Forked by 26 users
Languages   Python
🌐
PyPI
pypi.org › project › upgrade-requirements
upgrade-requirements
JavaScript is disabled in your browser. Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Reddit
reddit.com › r/djangolearning › how to keep your requirements.txt updated
r/djangolearning on Reddit: How to keep your requirements.txt updated
January 15, 2023 - Or you can spend the day learning pip-tools which automatically does the calculations for you. You give it the exact version of Django and package A and B that you want, and goes out and upgrades all the sub-packages as high as it can. It spits out a new requirements.txt with every packages pinned so pip knows exactly what it should install.
🌐
Rock and Null
paleblueapps.com › rockandnull › python-update-requirements-txt
How to keep your requirements.txt updated - Pale Blue
January 15, 2023 - Just pip install pur and you are ready to get started! ... Updated whitenoise: 5.1.0 -> 6.3.0 Updated stripe: 2.50.0 -> 5.0.0 Updated sentry-sdk: 1.5.12 -> 1.13.0 All requirements up-to-date.
🌐
GitHub
gist.github.com › extratone › 6724c1b95846ba9d136f56e1fc8f0421
How To Update All Python Packages - Gist - GitHub
Open a command shell by typing ‘powershell’ in the Search Box of the Task bar Update All Python Packages On Windows · $ pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_} ... Edit requirements.txt, and replace all ‘==’ ...
🌐
pkGUI
pkgui.com › pip
requirements.txt online update tool - pkgui.com
pip install <package-name>==<version>: Installs a specific version of a dependency. pip install --upgrade -r requirements.txt: Installs the latest versions of all dependencies specified in the requirements.txt file.
🌐
Reddit
reddit.com › r/learnpython › what in 'pip install -r requirements.txt' is making this take so many hours?
r/learnpython on Reddit: What in 'pip install -r requirements.txt' is making this take so many hours?
July 13, 2021 -

I did some changes on my local machine and updated requirements.txt. Then I pulled to my remote machine with git and did pip install -r requirements.txt, because as far as I understand this is supposed to only install new things.. right? What I want is to upgrade what has been upgraded and install what isn't already there. All my dependencies versions are specified in requirements.txt

But for every dependency, as far as I could see, this happened - for example for Jinja2==3.0.1:

Collecting Jinja2==3.0.1
  Using cached Jinja2-3.0.1-py3-none-any.whl (133 kB)
INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. If 
you want to abort this run, you can press Ctrl + C to do so. To improve how pip performs, tell us what happened here: https://pip.pypa.io/
surveys/backtracking
INFO: pip is looking at multiple versions of markupsafe to determine which version is compatible with other requirements. This could take 
a while.
INFO: pip is looking at multiple versions of itsdangerous to determine which version is compatible with other requirements. This could tak
e a while.

And it could stand like that for an hour or more. I went to bed at when I woke up, Pythonanywhere had put me in the "tar pit" because I was consuming too much CPU. Fair enough. But what am I doing wrong? What's with the 'using cached' and 'looking at multiple versions' - is this what is taking so long? Eventually I stopped the process.

Noob warning, sorry if I missed something obvious.

My two requirements.txt if that helps

My current requirements.txt:

alembic==1.6.5
appdirs==1.4.4
APScheduler==3.7.0
astroid==2.3.3
autopep8==1.5
bcrypt==3.2.0
blinker==1.4
cachelib==0.1.1
cairocffi==1.2.0
CairoSVG==2.5.2
certifi==2020.4.5.1
cffi==1.14.4
chardet==3.0.4
click==8.0.1
cryptography==3.3.1
cssselect2==0.4.1
defusedxml==0.6.0
distlib==0.3.1
dnspython==1.16.0
email-validator==1.1.0
entrypoints==0.3
env==0.1.0
filelock==3.0.12
flake8==3.7.9
Flask==2.0.1
Flask-DebugToolbar==0.11.0
Flask-Login==0.5.0
Flask-Mail==0.9.1
Flask-Migrate==3.0.1
Flask-Session==0.3.2
Flask-SQLAlchemy==2.4.1
Flask-User==1.0.2.2
Flask-WeasyPrint==0.6
Flask-WTF==0.14.3
html5lib==1.1
idna==2.9
importlib-metadata==1.7.0
ipapy==0.0.9.0
isort==4.3.21
itsdangerous==2.0.1
Jinja2==3.0.1
lazy-object-proxy==1.4.3
Mako==1.1.4
MarkupSafe==2.0.1
mccabe==0.6.1
passlib==1.7.4
Pillow==8.2.0
pipdeptree==1.0.0
pycodestyle==2.5.0
pycparser==2.20
pyflakes==2.1.1
pylint==2.4.4
pyparsing==2.4.6
Pyphen==0.10.0
python-dateutil==2.8.1
python-editor==1.0.4
pytz==2019.3
PyYAML==5.4.1
requests==2.23.0
scss==0.8.73
sentry-sdk==1.1.0
six==1.13.0
SQLAlchemy==1.3.16
tinycss2==1.1.0
tzlocal==2.1
ua-parser==0.10.0
urllib3==1.26.5
user-agents==2.2.0
WeasyPrint==52.1
webencodings==0.5.1
Werkzeug==2.0.1
wrapt==1.11.2
WTForms==2.3.1
zipp==3.1.0

My previous requirements.txt

appdirs==1.4.4
astroid==2.3.3
autopep8==1.5
bcrypt==3.2.0
blinker==1.4
cairocffi==1.2.0
CairoSVG==2.5.0
certifi==2020.4.5.1
cffi==1.14.4
chardet==3.0.4
Click==7.0
cryptography==3.3.2
cssselect2==0.4.1
defusedxml==0.6.0
distlib==0.3.1
dnspython==1.16.0
email-validator==1.1.0
entrypoints==0.3
env==0.1.0
filelock==3.0.12
flake8==3.7.9
Flask==1.1.1
Flask-DebugToolbar==0.11.0
Flask-Login==0.5.0
Flask-Mail==0.9.1
Flask-Session==0.3.1
Flask-SQLAlchemy==2.4.1
Flask-User==1.0.2.2
Flask-WeasyPrint==0.6
Flask-WTF==0.14.3
html5lib==1.1
idna==2.9
importlib-metadata==1.7.0
ipapy==0.0.9.0
isort==4.3.21
itsdangerous==1.1.0
Jinja2==2.11.3
lazy-object-proxy==1.4.3
MarkupSafe==1.1.1
mccabe==0.6.1
passlib==1.7.4
Pillow==8.1.2
pipdeptree==1.0.0
pycodestyle==2.5.0
pycparser==2.20
pyflakes==2.1.1
PyJWT==2.0.1
pylint==2.4.4
pyparsing==2.4.6
Pyphen==0.10.0
pytz==2019.3
requests==2.23.0
scss==0.8.73
six==1.13.0
SQLAlchemy==1.3.16
tinycss2==1.1.0
urllib3==1.25.8
WeasyPrint==52.1
webencodings==0.5.1
Werkzeug==0.16.0
wrapt==1.11.2
WTForms==2.3.1
zipp==3.1.0
Top answer
1 of 4
3
pip install --upgrade -r requirements.txt
2 of 4
2
is supposed to only install new things.. right? Why do you think so? No, not really. It may even downgrade things, but, generally, its not known what's going to happen. pip never guaranteed consistency between installs. The same requirements.txt may result in different stuff being installed. Do not use pip to install production-grade software. It's OK for development time, if you can then manually verify that what was installed is indeed what you wanted it to install. Otherwise, you are essentially, playing Black Jack. I think, recently, PiPA tried to add a constraint solver to pip, so that now it can be as slow as conda, with just as many unwarranted dependency conflicts. If you are on on version 20.3 or later, you may be using the new solver: https://github.com/pypa/pip/issues/988#issuecomment-713701684 . Like I said, pip isn't a tool for production deployment, but it's even worse with the new solver, as it's not properly tested yet. Testing the new solver implies not only testing its own mechanism, but it also means to test that the packages installed with new pip can properly formulate their dependencies. Since you have a huge list of packages, most of which are of quite low quality, it's quite predictable that you will run into such problems... In your specific case, it looks like there's simply a bug in pip, but, I'm sure idiots in PiPA will find a way to represent it as expected behavior. You specified that you want exact version of markupsafe, but it's searching for alternatives anyways. It's stupid, and a properly functioning package manager shouldn't do that, but pip is the way it is... Also, unsurprisingly, solving constraints, especially in Python is going to take forever, and use lots of CPU because writing optimized constraint solvers is just not a proper task for Python at this point. It's too slow, too poorly manages memory... but, it is what it is. Anyways, in practical terms, downgrade pip to something less than 20.2, and, it's likely that it will install what you want much faster. Except, it will be probably inconsistent, but, maybe that inconsistency doesn't really matter. A lot of package maintainers don't understand how dependencies work / wouldn't spend too much time figuring out what the exact requirements of a package are anyways. So, if it kinda worked for you before, it will probably still work.
🌐
OperaVPS
operavps.com › docs › pip update all packages to latest version
Pip Update All Packages to Latest Version [Pip Upgrade]
4 days ago - Virtual Environment (Recommended): Always perform upgrades in a virtual environment to avoid breaking system packages. Backup of Installed Packages: Save dependencies with pip freeze > requirements.txt to restore if needed.
🌐
Note.nkmk.me
note.nkmk.me › home › python
How to Install Python Packages with pip and requirements.txt | note.nkmk.me
April 16, 2025 - How to use pip (Install, update, uninstall packages) The following command installs multiple packages at once based on a configuration file, typically named requirements.txt.
🌐
Readthedocs
pynwb.readthedocs.io › en › stable › update_requirements.html
How to Update Requirements Files — PyNWB 3.1.2 documentation
cd pynwb # Set the requirements file to update: requirements-dev.txt or requirements-doc.txt target_requirements=requirements-dev.txt mkvirtualenv pynwb-requirements # Install updated requirements pip install -U -r $target_requirements # If relevant, you could pip install new requirements now ...