pip is just a PyPI package like any other; you could use it to upgrade itself the same way you would upgrade any package:
pip install --upgrade pip
On Windows the recommended command is:
py -m pip install --upgrade pip
Answer from Cairnarvon on Stack Overflowpip is just a PyPI package like any other; you could use it to upgrade itself the same way you would upgrade any package:
pip install --upgrade pip
On Windows the recommended command is:
py -m pip install --upgrade pip
The more safe method is to run pip though a python module:
python -m pip install -U pip
On windows there seem to be a problem with binaries that try to replace themselves, this method works around that limitation.
python - How to update/upgrade a package using pip? - Stack Overflow
python - How can I upgrade specific packages using pip and a requirements file? - Stack Overflow
How to upgrade all Python packages with pip - Stack Overflow
Upgrade pip
Can I use `pip install --upgrade pip` to upgrade PIP?
Will upgrading PIP affect my existing Python packages?
How often should I upgrade PIP?
Videos
To upgrade pip using pip is a bit different than regular command. Use
python -m pip install --upgrade pip
Here python -m will read the pip library file as a script and you will be able to update.
If you were like me you had created a virtual environment in a project folder.
python -m venv env
So in order to make the pip upgrade work, go into the Scripts folder of the env folder.
Then run .\python -m pip install --upgrade pip.
Ditto with any pip installs. Same folder .\pip install ....
The .\ pins it to the command in the current folder, be it pip or python.
(I was doing this on Windows. But ./ would be the equivalent for Unix variants)
PS: I also ran those commands as Administrator - so sudo the commands if things fails.
This is the way
Copypip install <package_name> --upgrade
or in short
Copypip install <package_name> -U
Using sudo will ask to enter your root password to confirm the action, but although common, is considered unsafe.
If you do not have a root password (if you are not the admin) you should probably work with virtualenv.
You can also use the user flag to install it on this user only.
Copypip install <package_name> --upgrade --user
For a non-specific package and a more general solution, you can check out pip-review. A tool that checks what packages could/should be updated.
To install:
Copy$ pip install pip-review
Then run:
Copy$ pip-review --interactive
requests==0.14.0 is available (you have 0.13.2)
Upgrade now? [Y]es, [N]o, [A]ll, [Q]uit y
» pip install upgrade-pip
I ran the following command and it upgraded from 1.2.3 to 1.4.0
Copypip install Django --upgrade
Shortcut for upgrade:
Copypip install Django -U
Note: if the package you are upgrading has any requirements this command will additionally upgrade all the requirements to the latest versions available. In recent versions of pip, you can prevent this behavior by specifying --upgrade-strategy only-if-needed. With that flag, dependencies will not be upgraded unless the installed versions of the dependent packages no longer satisfy the requirements of the upgraded package.
According to pip documentation example 3:
Copypip install --upgrade django
But based on my experience, using this method will also upgrade any package related to it. Example:
Assume you want to upgrade somepackage that require Django >= 1.2.4 using this kind of method it will also upgrade somepackage and django to the newest update. Just to be safe, do:
Copy# Assume you want to keep Django 1.2.4
pip install --upgrade somepackage django==1.2.4
Doing this will upgrade somepackage and keeping Django to the 1.2.4 version.
Sent through a pull-request to the pip folks; in the meantime use this pip library solution I wrote:
Copyfrom operator import attrgetter
## Old solution:
# from pip import get_installed_distributions
# from pip.commands import install
## New solution:
from pkg_resources import working_set
from pip._internal.commands import install
install_cmd = install.InstallCommand()
options, args = install_cmd.parse_args(
## Old solution:
# list(map(attrgetter("project_name")
# get_installed_distributions()))
## New solution:
list(map(attrgetter("project_name"), working_set))
)
options.upgrade = True
install_cmd.run(options, args) # Chuck this in a try/except and print as wanted
This seemed to work for me...
Copypip install -U $(pip list --outdated | awk '{printf $1" "}')
I used printf with a space afterwards to properly separate the package names.