Install and upgrade Python packages using pip on Windows, Linux, and Mac

Renesh Bedre    2 minute read

Install and upgrade Python packages

  • pip is Python’s official package manager and is a recommended method for installing, upgrading, and uninstalling the Python packages.
  • Check below how to install and upgrade the pip on Windows, Linux, and Mac for managing the Python packages

Installing and upgrading pip

  • pip is a package (bundle of software) installer for Python.
  • In order to use pip, it is required to install Python (Python 3 >=3.4). You can check here for installing Python 3 on Windows, Linux, and Mac from the source. Additionally, you can also check the Python installation guide for installing Python from OS specific package manager.

Note: If you have installed Python 3 from the source, you should add the Python executable in the system path variable to be able to run Python commands from any path in OS. Check how to add Python executable in system path variable for Windows, Linux, and Mac

Check pip version

  • If you have already installed Python 3 (>=3.4), you can run the below shell command to check the pip version
# Windows, Linux, and Mac
# using pip
pip --version
# output if installed
pip 20.1.1

python -m pip --version
# output if installed
pip 20.1.1

If pip is not installed, use ensurepip to install pip (see below)

Install pip using ensurepip and conda

# Windows, Linux, and Mac
python -m ensurepip --default-pip

# within conda environment
conda install pip

upgrading pip to the latest version

# Windows, Linux, and Mac
# using pip
pip install --upgrade pip

# using Python
python -m pip install --upgrade pip

Installing a specific version of pip

# Windows, Linux, and Mac
# using pip
pip install --upgrade pip==21.0.1

# using Python
python -m pip install --upgrade pip==21.0.1

# using easy_install (deprecated)
easy_install pip==21.0.1

Installing and upgrading Python packages using pip

Installing Python packages

# Windows, Linux, and Mac
# using pip (replace bioinfokit with required python package name)
pip install bioinfokit

# using Python
python -m pip install bioinfokit

Upgrading installed Python packages to the latest version

# Windows, Linux, and Mac
# using pip (replace bioinfokit with required python package name)
pip install --upgrade bioinfokit

# using Python
python -m pip install --upgrade bioinfokit

# upgrade all installed packages at same time using pip-review (need to install pip-review package)
pip-review --auto

Install a specific version of Python packages

# Windows, Linux, and Mac
# using pip (replace bioinfokit with required python package name)
pip install --upgrade bioinfokit==2.0.0

# using Python
python -m pip install --upgrade bioinfokit==2.0.0

Install specific packages from requirements files

requirements file (requirements.txt) contains the name of Python packages that need to be installed

# Windows, Linux, and Mac
# using pip
pip install -r requirements.txt

# using Python
python -m pip install -r requirements.txt

Uninstall Python packages

# Windows, Linux, and Mac
# using pip (replace bioinfokit with required python package name)
pip uninstall bioinfokit

# using Python
python -m pip uninstall bioinfokit

Check Python package version

# Windows, Linux, and Mac
# using pip (replace bioinfokit with required python package name)
pip show bioinfokit
# output
Name: bioinfokit
Version: 2.0.4
...

pip freeze # it will list all installed packages with their version
# output
adjustText==0.7.3
bioinfokit==2.0.4
...

# using Python
python -c "import bioinfokit; print(bioinfokit.__version__)"
2.0.4

# using Python interpreter
>>> import bioinfokit
>>> bioinfokit.__version__
'2.0.4'

References

If you have any questions, comments or recommendations, please email me at reneshbe@gmail.com

This work is licensed under a Creative Commons Attribution 4.0 International License

Tags:

Updated: