0
0
PythonHow-ToBeginner · 3 min read

How to Install pip in Python: Step-by-Step Guide

To install pip in Python, first check if it is already installed by running python -m pip --version. If not installed, download get-pip.py from the official site and run python get-pip.py in your command line to install pip.
📐

Syntax

Use the following command to check if pip is installed:

  • python -m pip --version: Shows the installed pip version.
  • python get-pip.py: Runs the installer script to install pip.

Here, python runs the Python interpreter, -m pip runs the pip module, and get-pip.py is the installation script.

bash
python -m pip --version
python get-pip.py
💻

Example

This example shows how to download the get-pip.py script and install pip on your system.

bash
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
python -m pip --version
Output
Collecting pip Downloading pip-23.1.2-py3-none-any.whl (2.1 MB) Installing collected packages: pip Successfully installed pip-23.1.2 pip 23.1.2 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
⚠️

Common Pitfalls

Common mistakes when installing pip include:

  • Not running the command with the correct Python version if multiple versions are installed.
  • Not having administrator or root permissions to install packages.
  • Trying to install pip without internet access to download the installer.

Always run the command prompt or terminal as administrator or use sudo on Linux/macOS if needed.

bash
python get-pip.py
# Wrong: Running without permissions may cause errors

sudo python get-pip.py
# Right: Using sudo on Linux/macOS to get permissions
📊

Quick Reference

CommandDescription
python -m pip --versionCheck if pip is installed and see its version
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.pyDownload the pip installer script
python get-pip.pyRun the installer script to install pip
sudo python get-pip.pyRun installer with admin rights on Linux/macOS

Key Takeaways

Check if pip is already installed using 'python -m pip --version'.
Download 'get-pip.py' from the official source to install pip if missing.
Run the installer script with proper permissions to avoid errors.
Use 'sudo' on Linux/macOS if you get permission denied errors.
Ensure you use the correct Python version if multiple are installed.