How To Install & Upgrade Pip In Cmd

Python comes with a package installer called `pip` that is used to install Python packages from the Python Package Index (PyPI). If you have a Python version of 2.7.9 or later, or Python 3.4 or later, `pip` should already be installed. However, if you have an older version or it’s missing for some reason, you can use the following method to install `pip` using Python.

1. How To Install Pip In Cmd Use Python.

1.1 Download the `get-pip.py` script.

Open your web browser and go to the following link. To install pip for Python 2.7 : https://bootstrap.pypa.io/pip/2.7/get-pip.pyTo install pip for Python3.7 or above : https://bootstrap.pypa.io/get-pip.py.

Right-click on the page and choose “Save Page As” to download the `get-pip.py` script to your computer. If you use Safari web browser on macOS, you should check the Page Source item from the Format drop down list in the Save As dialog window. Otherwise, Safari will save the file in webarchive format that make the file content not readable.

Then when you run the command python ./get-pip.py in below section, it will throw the error SyntaxError: Non-ASCII character ‘\xd1’ in file ./get-pip.py on line 1, but no encoding declared.

1.2 Open a terminal or command prompt.

Open a terminal on macOS or Linux, or a command prompt on Windows.

1.3 Navigate to the directory containing the `get-pip.py` script.

Use the `cd` command to change to the directory where you downloaded the `get-pip.py` script. For example, if you downloaded it to your “Downloads” folder on macOS or Linux, use the following command.

cd ~/Downloads

On Windows, if you downloaded it to your “Downloads” folder on drive C, use:

cd C:\Users\YourUsername\Downloads

1.4 Run the `get-pip.py` script.

Now that you’re in the correct directory, run the following command to execute the `get-pip.py` script use Python.

1.4.1 For Python2.

For Python 2, run the command python ./get-pip.py on macOS.

% python ./get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Collecting pip<21.0
  Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 1.1 MB/s 
Installing collected packages: pip
  WARNING: The scripts pip, pip2 and pip2.7 are installed in '/Users/administrator/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.

From the above output, we can see it has installed pip, pip2 and pip2.7 successfully in the folder /Users/administrator/Library/Python/2.7/bin, but it does not add them in the PATH environment variable. So you can run the command below to see the pip version.

% /Users/administrator/Library/Python/2.7/bin/pip --version
pip 20.3.4 from /Users/administrator/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)
 
% /Users/administrator/Library/Python/2.7/bin/pip2 --version
pip 20.3.4 from /Users/administrator/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)

% /Users/administrator/Library/Python/2.7/bin/pip2.7 --version
pip 20.3.4 from /Users/administrator/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)

Or you can add the path /Users/administrator/Library/Python/2.7/bin in the system environment variable PATH. Then you can run the command pip –version, pip2 –version, or pip2.7 –version directly in console.

1.4.2 For Python3.

For Python 3, run the command python3 get-pip.py on macOS.

python3 get-pip.py

If you have multiple Python versions installed on your system, make sure to use the appropriate command for the version you want to install `pip` for.

% /usr/local/bin/python3.10 ./get-pip.py 
Collecting pip
  Obtaining dependency information for pip from https://files.pythonhosted.org/packages/50/c2/e06851e8cc28dcad7c155f4753da8833ac06a5c704c109313b8d5a62968a/pip-23.2.1-py3-none-any.whl.metadata
  Downloading pip-23.2.1-py3-none-any.whl.metadata (4.2 kB)
Collecting wheel
  Obtaining dependency information for wheel from https://files.pythonhosted.org/packages/17/11/f139e25018ea2218aeedbedcf85cd0dd8abeed29a38ac1fda7f5a8889382/wheel-0.41.0-py3-none-any.whl.metadata
  Downloading wheel-0.41.0-py3-none-any.whl.metadata (2.2 kB)
Downloading pip-23.2.1-py3-none-any.whl (2.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 4.0 MB/s eta 0:00:00
Downloading wheel-0.41.0-py3-none-any.whl (64 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 64.7/64.7 kB 3.6 MB/s eta 0:00:00
Installing collected packages: wheel, pip
  WARNING: The script wheel is installed in '/Library/Frameworks/Python.framework/Versions/3.10/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  Attempting uninstall: pip
    Found existing installation: pip 23.0.1
    Uninstalling pip-23.0.1:
      Successfully uninstalled pip-23.0.1
  WARNING: The scripts pip, pip3 and pip3.10 are installed in '/Library/Frameworks/Python.framework/Versions/3.10/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.2.1 wheel-0.41.0

From the above output, we can see it has installed pip, pip3 and pip3.10 successfully in the folder /Library/Frameworks/Python.framework/Versions/3.10/bin, but it does not add them in the PATH environment variable.

If you want to find where the newly pip3 is installed, you can run the command which pip3 to get it’s installed directory, and then go to the directory to see other pip versions. You can see that the pip3, pip3.10, and pip3.11 in the folder /usr/local/bin are all link files to the above pip3 executable files.

% which pip3
/usr/local/bin/pip3
% ls -l /usr/local/bin/pip*
lrwxrwxr-x  1 root  admin  67 Jul 28 04:29 /usr/local/bin/pip3 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/pip3
lrwxrwxr-x  1 root  admin  70 Jul 28 04:29 /usr/local/bin/pip3.10 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/pip3.10
lrwxrwxr-x  1 root  admin  70 Jul 21 00:39 /usr/local/bin/pip3.11 -> ../../../Library/Frameworks/Python.framework/Versions/3.11/bin/pip3.11

You can get the installed different pips version with the below command.

% /usr/local/bin/pip3.10 --version
pip 23.2.1 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)

% /usr/local/bin/pip3.11 --version
pip 23.1.2 from /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)

2. Verify `pip` installation.

Once the installation process is complete, you can verify that `pip` is installed by running the following command.

For Python 2.

pip --version

For Python 3.

pip3 --version

You should see the version number of `pip` displayed, indicating that it’s successfully installed.

Now you have `pip` installed and ready to use. You can use `pip` to install various Python packages by simply typing `pip install packagename` or `pip3 install packagename` in the terminal or command prompt. Replace `packagename` with the name of the Python package you want to install.

3. How To Upgrade Pip Version.

3.1 How To Upgrade Pip To The Latest Version.

Here’s a step-by-step guide on how to upgrade pip to the latest version. Open a terminal on macOS or Linux, or a command prompt on Windows. Type one of the following commands based on your Python version and press Enter to upgrade pip.

For Python 2: pip install –upgrade pip or pip2 install –upgrade pip.

% /Users/administrator/Library/Python/2.7/bin/pip2 install --upgrade pip
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: pip in /Users/administrator/Library/Python/2.7/lib/python/site-packages (20.3.4)

For Python 3: pip install –upgrade pip or pip3 install –upgrade pip.

% pip3 install --upgrade pip
Requirement already satisfied: pip in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (23.2.1)
% 
% pip3 --version
pip 23.2.1 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)

If you have multiple Python versions installed on your system, make sure to use the appropriate command for the version of pip you want to upgrade.

For example, I installed both python 3.10 & python 3.11 on my macOS.

% ls -l /usr/local/bin/python*
lrwxr-xr-x  1 root  wheel  70 Jul 28 04:28 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3
lrwxr-xr-x  1 root  wheel  77 Jul 28 04:28 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3-config
lrwxr-xr-x  1 root  wheel  78 Jul 28 04:28 /usr/local/bin/python3-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3-intel64
lrwxr-xr-x  1 root  wheel  73 Jul 28 04:28 /usr/local/bin/python3.10 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10
lrwxr-xr-x  1 root  wheel  80 Jul 28 04:28 /usr/local/bin/python3.10-config -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10-config
lrwxr-xr-x  1 root  wheel  81 Jul 28 04:28 /usr/local/bin/python3.10-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10-intel64
lrwxr-xr-x  1 root  wheel  73 Jul 21 00:37 /usr/local/bin/python3.11 -> ../../../Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11
lrwxr-xr-x  1 root  wheel  80 Jul 21 00:37 /usr/local/bin/python3.11-config -> ../../../Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11-config
lrwxr-xr-x  1 root  wheel  81 Jul 21 00:37 /usr/local/bin/python3.11-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11-intel64
% 
% ls -l /usr/local/bin/pip*   
lrwxrwxr-x  1 root  admin  67 Jul 28 04:29 /usr/local/bin/pip3 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/pip3
lrwxrwxr-x  1 root  admin  70 Jul 28 04:29 /usr/local/bin/pip3.10 -> ../../../Library/Frameworks/Python.framework/Versions/3.10/bin/pip3.10
lrwxrwxr-x  1 root  admin  70 Jul 21 00:39 /usr/local/bin/pip3.11 -> ../../../Library/Frameworks/Python.framework/Versions/3.11/bin/pip3.11

If you want to upgrade pip for python 3.11, then you can run the below command.

% /usr/local/bin/pip3.11 --version
pip 23.1.2 from /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)
% 
% /usr/local/bin/pip3.11 install --upgrade pip
Requirement already satisfied: pip in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (23.1.2)
Collecting pip
  Using cached pip-23.2.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.1.2
    Uninstalling pip-23.1.2:
      Successfully uninstalled pip-23.1.2
Successfully installed pip-23.2.1
%
% /usr/local/bin/pip3.11 --version            
pip 23.2.1 from /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)

Besides using pip, you can also use python to upgrade your pip version to the latest version, then the command is python -m pip install –upgrade pip or python3 -m pip install –upgrade pip. Below is an example.

% /usr/local/bin/pip3 --version
pip 23.1.2 from /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)
% 
% /usr/local/bin/python3 -m pip install --upgrade pip
Requirement already satisfied: pip in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (23.1.2)
Collecting pip
  Downloading pip-23.2.1-py3-none-any.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 4.2 MB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.1.2
    Uninstalling pip-23.1.2:
      Successfully uninstalled pip-23.1.2
  WARNING: The scripts pip, pip3 and pip3.11 are installed in '/Library/Frameworks/Python.framework/Versions/3.11/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.2.1
%
% /usr/local/bin/pip3 --version                      
pip 23.2.1 from /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip (python 3.11)

3.2 How To Upgrade Pip To The Specified Version.

Run the command python3 -m pip install pip==version-number to upgrade pip version to the specified version.

% sudo /usr/local/bin/python3 -m pip install pip==18.1    
Collecting pip==18.1
  Downloading pip-18.1-py2.py3-none-any.whl (1.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 3.4 MB/s eta 0:00:00
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 23.2.1
    Uninstalling pip-23.2.1:
      Successfully uninstalled pip-23.2.1
  WARNING: The scripts pip, pip3 and pip3.11 are installed in '/Library/Frameworks/Python.framework/Versions/3.11/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-18.1

Then run the command /usr/bin/pip3 –version to get the new pip3 version.

% /usr/bin/pip3 --version              
pip 18.1 from /Library/Python/3.8/site-packages/pip (python 3.8)

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.