Installation#
If your Python environment does not have pip installed, there are 2 mechanisms to install pip supported directly by pip’s maintainers:
ensurepip #
Python comes with an ensurepip module [ 1 ] , which can install pip in a Python environment.
More details about how ensurepip works and how it can be used, is available in the standard library documentation.
get-pip.py #
This is a Python script that uses some bootstrapping logic to install pip.
Open a terminal/command prompt, cd to the folder containing the get-pip.py file and run:
More details about this script can be found in pypa/get-pip’s README.
Standalone zip application#
The zip application is currently experimental. We test that pip runs correctly in this form, but it is possible that there could be issues in some situations. We will accept bug reports in such cases, but for now the zip application should not be used in production environments.
In addition to installing pip in your environment, pip is available as a standalone zip application. This can be downloaded from https://bootstrap.pypa.io/pip/pip.pyz. There are also zip applications for specific pip versions, named pip-X.Y.Z.pyz .
The zip application can be run using any supported version of Python:
If run directly:
then the currently active Python interpreter will be used.
Alternative Methods#
Depending on how you installed Python, there might be other mechanisms available to you for installing pip such as using Linux package managers .
These mechanisms are provided by redistributors of pip, who may have modified pip to change its behaviour. This has been a frequent source of user confusion, since it causes a mismatch between documented behaviour in this documentation and how pip works after those modifications.
If you face issues when using Python and pip installed using these mechanisms, it is recommended to request for support from the relevant provider (eg: Linux distro community, cloud provider support channels, etc).
Upgrading pip #
Upgrade your pip by running:
Compatibility#
The current version of pip works on:
Windows, Linux and MacOS.
CPython 3.7, 3.8, 3.9, 3.10 and latest PyPy3.
pip is tested to work on the latest patch version of the Python interpreter, for each of the minor versions listed above. Previous patch versions are supported on a best effort approach.
Other operating systems and Python versions are not supported by pip’s maintainers.
Users who are on unsupported platforms should be aware that if they hit issues, they may have to resolve them for themselves. If they received pip from a source which provides support for their platform, they should request pip support from that source.
The ensurepip module was added to the Python standard library in Python 3.4.
How to upgrade your pip package to the latest version
Pip is a useful tool for managing and installing python packages. Here's how to upgrade it on various operating systems.
BitLaunch
Read more posts by this author.
BitLaunch
Pip is the defacto tool for managing and installing your Python packages. It lets you install third-party software packages that are listed in the Python Package Index (PyPi), extending functionality for developers and allowing regular users to install certain applications written in Python.
Pip is usually bundled with Python and updates automatically, but you might want to manually upgrade and manage it. This is what we’ll be teaching you today. This process should work whether you’re using pip on Linux, Windows, or macOS.
Checking your pip version
The first thing you’ll probably want to do is check which pip version you have in the first place. You can then compare that to the latest published version to see whether you should upgrade. The command for this is thankfully very simple:
Your output should look something like this:
You can check what the latest pip version is here and decide whether to update accordingly. At the time of writing, the latest pip version is 22.0.4. Our server is on 20.0.2, so an upgrade is definitely in order.
How to upgrade pip
Upgrading pip is again very easy process. Just run the following:
Bear in mind that this command will try to uninstall the current version and replace it with the new one.
Upgrading pip on Ubuntu
If you see the message Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr , it’s because you’re using Ubuntu. The Ubuntu version of pip has been modified to disallow upgrades via this method. Instead, you must use the Ubuntu packaging system.
Note the Ubuntu package probably won’t be up to date. If you do need the latest version, you can download get-pip.py and run it. However, it’s worth noting that running pip as the root user can cause broken permissions and conflicting behavior with the system package manager. You are generally better off using a virtual environment.
Here are the commands you need:
How to downgrade pip
If you do find that you need to rollback your pip version due to bugs, incompatibilities, or any other reason, find the version number you want to roll back to and then run this command:
How to update Python packages with pip
Pip also allows you to manually update individual Python packages. We can use matplotlib as an example:
That about covers it. Pip is a versatile and useful tool and know you should now understand it a little better.
If you like to do your development in the cloud, feel free to check out our high-speed, anonymous VPS servers.
How to add SSL to Nginx
SSL keeps your user’s information secure and helps your website rank on search engines. Here’s how to set it up on Nginx.
Introducing: Fast SSL setup with the BitLaunch LEMP app
Add SSL to your Nginx server with a single command via the BitLaunch LEMP app.
How can I upgrade pip to the latest version?
I installed pip using get-pip.py , but the following error happened after pip freeze gets executed:
I’ve checked that pip version 1.7 is the latest one. However, updating pip via pip install -U pip did not update my pip. How can I fix this problem?
10 Answers 10
I usually just run the following commands to upgrade both pip2 (= pip by default) and pip3 :
You must make sure that you upgrade the version (for Python 2 or 3), which you want to react on the command pip without number, last.
Also please note that this keeps the old packaged versions installed through apt-get or any other package manager, but adds new versions which have nothing to do with the system packages. The pip -installed packages will be preferred, but you should not remove the apt-get -installed ones either, because the package manager can’t know that any pip version is installed otherwise.
command does not work properly anymore. The correct command should be:
P.S. If you want to make sure your other Python packages are also up to date, follow the instructions here.
Copy (or download) the source link (ends in .tar.gz ).
The version should be changed to the latest version and the link can be updated with the latest version’s link.
This should work.
I think it’s worth mentioning that what I’m explaining below is if you expect pip to point to Python 2 and pip3 to point to Python 3. The reason I mention this is because when you upgrade pip3, it also takes over the pip command as well. This is a somewhat strange convention because by default python points to 2.x and python3 points to 3.x. That being said.
If you want to have the latest versions of python 2.x pip and python 3.x pip3 coexist on the same machine (using pip for 2.x and pip3 for 3.x), you need to do the following:
The other answers provided by others fail to mention that after running sudo pip3 install pip —upgrade you’ll end up with the pip command installing packages in the python 3.x directories instead of the python 2.x directories.
Part of me thinks that we should just leave pip be after upgrading pip3 (even if it pip -> pip3), but there’s a danger there that people already have an expectation that pip functions like python — both pointing to python 2.x. In other words, people are probably trained to use pip/python for python 2.x just like they are trained to use pip3/python3 for python 3.x.
How to upgrade pip3?
I want to use python3.5 for development, but many times when I install the module for python 3.5, it always fails. The terminal tells me that a higher version is available, but it doesn’t work when I upgrade it.
12 Answers 12
You are using pip3 to install flask-script which is associated with python 3.5. However, you are trying to upgrade pip associated with the python 2.7, try running pip3 install —upgrade pip .
It might be a good idea to take some time and read about virtual environments in Python. It isn’t a best practice to install all of your packages to the base python installation. This would be a good start: http://docs.python-guide.org/en/latest/dev/virtualenvs/
To upgrade your pip3, try running:
Your pip may move from /bin to /usr/local/bin
To upgrade pip as well, you can follow it by:
Try this command:
First decide which pip you want to upgrade, i.e. just pip or pip3. Mostly it’ll be pip3 because pip is used by the system, so I won’t recommend upgrading pip.
The difference between pip and pip3 is that
NOTE: I’m referring to PIP that is at the BEGINNING of the command line.
pip is used by python version 2, i.e. python2
pip3 is used by python version 3, i.e. python3
For upgrading pip3: # This will upgrade python3 pip.
For upgrading pip: # This will upgrade python2 pip.
This will upgrade your existing pip to the latest version.
The Problem
You use pip (the Python 2 one). Now you want to upgrade pip (the Python 3 one). After that, pip is the Python 3 one.
The solution
Use pip2 and pip3 . This way it is explicit.
If you want to use pip , just check where it is ( which pip ) and change the link. For example:
What worked for me was the following command:
pip3 install —upgrade pip worked for me
In Ubuntu 18.04, below are the steps that I followed.
For some reason you will be getting an error, and that be fixed by making bash forget the wrongly referenced locations using the following command.
If you have 2 versions of Python (eg: 2.7.x and 3.6), you need do:
- add the path of 2.x to system PATH
- add the path of 3.x to system PATH
- pip3 install —upgrade pip setuptools wheel
for example, in my .zshrc file:
You can exec command pip —version and pip3 —version check the pip from the special version. Because if don’t add Python path to $PATH, and exec pip3 install —upgrade pip setuptools wheel , your pip will be changed to pip from python3, but the pip should from python2.x
This worked for me (mac)
If you try to run
you will get the following error:
but if you upgrade using the suggested command:
then, the legacy pip will be upgraded, so what I did is the following:
and I located my pip3 installation (just in case the following command wouldn’t upgrade the legacy pip. Then i changed to that directory and upgraded pip3 using the following commands: (your directory could be different)