Installing, uninstalling, or upgrading Python modules using Pip (Linux - RHEL7) (2024)

Python modules are packages, or modules, which can be imported into a project to use. This includes packages like matplotlib, numpy, flask, and many more. To install and uninstall packages for Python you need to use Pip; PIP is a package manager for Python packages, or modules.

Python modules that are stored on your home drive, will only be accessible by you. Other students, faculty, and staff that require the same packages will have to individually run the following commands as well for shared Python projects.

Fully managed RHEL7 Linux systems currently support Python 2.7, Python 3.4, and Python 3.6, these can be launched via their respective commands: “python, python3.4, and python3.6”.

Determining which version of Pip to use

Determine which version of Python you would like to install the package for, for each version of python there is a respective pip manager.

Python version table
Python VersionPython CommandPip Command
Python 2.7pythonpip
Python 3.4python3.4pip3.4
Python 3.6python3.6pip3.6

In all of the following examples below replace the variable ‘$PIP’ with the respective pip command.

Note: The command python3 and pip3 currently map to python3.6 and pip3.6, respectively.

Installing Python packages using Pip

In this example, flask will be installed and uninstalled. Flask is a package used for front-end Python web-development.

  1. Open a terminal.
  2. To install a package use the command '$PIP install --user <package-name>' where $PIP is the Pip Version command in the above table.
    1. This example will install the flask package.
      1. In this example using Python 2.7: 'pip install --user flask'
      2. For Python 3.6 this would be 'pip3.6 install --user flask'
    2. This will import the flask package and its dependencies if it has any.Installing, uninstalling, or upgrading Python modules using Pip (Linux - RHEL7) (1)

Uninstalling/removing Python packages using Pip

  1. Open a terminal window.
  2. To uninstall, or remove, a package use the command '$PIP uninstall <package-name>'.
    1. This example will remove the flask package.
      1. In this example using Python 2.7: 'pip uninstall - flask'
      2. For Python 3.6 this would be 'pip3.6 uninstall --user flask'
    2. NOTE: You will be unable to remove packages installed directly on the system
  3. The command will ask for confirmation after listing the files to be removed. Confirm this action by typing ‘y' then Enterkey.Installing, uninstalling, or upgrading Python modules using Pip (Linux - RHEL7) (2)

Upgrading a Python package using Pip

If you wish to update a Python module you can do so with the '--upgrade' flag

  1. Open a terminal.
  2. To upgrade a package use the command '$PIP install --upgrade --user <package-name>'
    1. This example will upgrade the numpy package:
      1. In this example using Python 2.7: 'pip install --upgrade --user numpy'
      2. For Python 3.6 this would be 'pip3.6 install --upgrade --user numpy'
    2. NOTE: You will be unable to upgrade packages installed locally on the systemInstalling, uninstalling, or upgrading Python modules using Pip (Linux - RHEL7) (3)

Location of installed Python packages through Pip

By default Python packages installed through pip using the '--user' flag will be stored in one of the following locations in your home directory, depending on which version of python you installed the package for:

Note: ~ is your home directory location, also equivalent to $HOME .

~/.local/lib/python2.7/site-packages

~/.local/lib/python3.4/site-packages

~/.local/lib/python3.6/site-packages

Installing, uninstalling, or upgrading Python modules using Pip (Linux - RHEL7) (4)

By default, Python packages installed locally on each system will be stored in one of the following directories, depending on which version of python packages you are looking for:

/usr/lib/python2.7/site-packages

/usr/lib/python3.4/site-packages

/usr/lib/python3.6/site-packages

Installing, uninstalling, or upgrading Python modules using Pip (Linux - RHEL7) (5)

Cleanly managing python modules

When working on many different python programs you may run into issues regarding conflicts between modules that you have installed. One option python offers to manage this is the usage of Virtual Environments which contain everything needed to run the program inside of your virtual environment directory.

Python 2.7 does not incorporate virtual environments by default, however, there is a module to handle this called Virtualenv.

Python 3.4 and 3.6 have this feature built-in, as seen from here from theofficial Python documentation. The Virtualenv module is also available for Python 3.4 and Python 3.6.

Installing, uninstalling, or upgrading Python modules using Pip (Linux - RHEL7) (2024)

FAQs

How to install Python pip on RHEL 7? ›

Here are some example steps for using pip from RHSCL on RHEL7:
  1. Install the pip from SCL as root. # subscription-manager repos --enable rhel-server-rhscl-7-rpms # yum install python27-python-pip.
  2. Switch to a normal user and check the pip. $ scl enable python27 bash $ which pip $ pip -V.
May 27, 2020

How do I update Python module with pip? ›

Basic Use: The fundamental command to update a Python package using pip is pip install --upgrade package-name . This command tells pip to find the latest version of the specified package and install it, replacing the old version if it exists.

How to install Python modules in Linux using pip? ›

Installing, uninstalling, and upgrading Python packages using Pip
  1. Open a terminal window.
  2. Use the command ' $PIP install --user <package-name> ' where $PIP is the Pip Version command referenced in the Python version table. Using Python 2.7: 'pip install --user flask' Using Python 3.6: 'pip3.6 install --user flask'
Nov 6, 2018

How to uninstall Python modules using pip? ›

Steps involved for uninstalling using pip

Open the command prompt. With the help of "PIP uninstall module_name” command, uninstall the module. The flask package will be deleted. In the Python 2.7 version, flask uninstall through pip.

How to upgrade Python using pip in Linux? ›

Run the command python -m pip install --upgrade pip to update Pip. If this command doesn't work on Windows, use py -m pip install --upgrade pip instead. If you get permissions errors in Linux, run sudo python -m pip install --upgrade pip .

How to install specific Python module version using pip? ›

To install a specific version of a package using pip in python, you can use the package name followed by the version number you want to install and use the == operator. In the above example, we are installing version 2.0. 1 of the package 'example-package'. This will install all versions greater than or equal to 2.0.

How to upgrade Python on Linux? ›

One common method to update Python on Linux is through the package manager provided by your distribution (e.g., apt, dnf, etc.). This method allows you to easily update Python along with other system packages.

How to install Python packages in Linux? ›

Installing Python Packages with Setup.py

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

How to install module command in Linux? ›

Installation instructions
  1. cd to the directory containing the package's source code. ...
  2. Type ./configure to adapt the installation for your system. ...
  3. Type make to adapt scripts to the configuration, build Tcl extension library if enabled and build documentation if working from git repository.

How do I uninstall all Python modules? ›

PIP Uninstall All Packages

It can help you list all the installed packages via PIP and uninstall them without asking for confirmation. The correct type of this command is pip uninstall -y -r <(pip freeze). pip uninstall -r requirements. txt This helps to uninstall packages one by one.

How do I install all Python packages at once? ›

If you need to install multiple packages at once in Python, then it is a simple task. All we have to do is create a file and write the names of all the packages there and save it in the form of “. txt”. Once the file is created open the command prompt and hit the install command followed by the file name.

How to uninstall Python package with pip in Linux? ›

Quick Pip Uninstallation Steps
  1. Open your terminal or command prompt.
  2. Start the command with python (Unix/macOS) or py (Windows).
  3. Write pip -m uninstall [packagename].
  4. Press Enter/Return to execute the command.
  5. Type y to confirm the uninstallation.
Mar 9, 2024

How to uninstall Python module command? ›

Install Modules with pip
  1. Ensure the pip module is already installed. ...
  2. Verify the release of pip to ensure it is installed correctly. ...
  3. Install the new Python module using the command pip install <module-name> . ...
  4. To list all installed Python modules and packages, use the pip list command.
Jan 28, 2022

How to use pip command? ›

You can use pip from the command line by typing pip followed by a command, such as install to install a package or uninstall to remove a package. For example, to install the popular NumPy package, you can type pip install numpy in the command prompt.

How to install pip in Linux 7? ›

You can install PIP on CentOS 7 with the following 2 steps.
  1. Step 1: SSH into your VPS. First, you need to SSH into your VPS as root, if you don't know how to SSH, you can see the instructions below: How to log in to Linux VPS via SSH protocol.
  2. Step 2: Install PIP and use PIP. Enable the EPEL repository.
Feb 21, 2023

How to install python3 pip in redhat? ›

How to Install PIP3 in Linux
  1. Verify Python Installation. Before installing pip3, it's essential to ensure that Python 3 is installed on your Linux system. ...
  2. Update Package Manager. Ensure that your system's package manager is up to date. ...
  3. Install pip3 in Linux. ...
  4. Verify pip3 Installation in Linux.
Jan 23, 2024

How to install Python packages on RHEL? ›

How to Install Python 3 / Python 2.7 on RHEL 8
  1. Open the Terminal application or window.
  2. Search for python package in RHEL 8, run: sudo yum search python3.
  3. To install python 3 on RHEL 8, run: sudo yum install python3.
  4. To install python 2 on RHEL 8, run: sudo yum install python2.
Mar 5, 2019

How to install pip with apt? ›

You can install Pip in Ubuntu using the simple “apt install” command. The command for Pip 3 is “$ sudo apt install Python3-pip”, and the command for Pip 2 is “$ sudo apt install Python-pip.” Pip is a handy command-line tool that allows you to install and manage Python Software Packages.

Top Articles
Latest Posts
Article information

Author: Fr. Dewey Fisher

Last Updated:

Views: 6105

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Fr. Dewey Fisher

Birthday: 1993-03-26

Address: 917 Hyun Views, Rogahnmouth, KY 91013-8827

Phone: +5938540192553

Job: Administration Developer

Hobby: Embroidery, Horseback riding, Juggling, Urban exploration, Skiing, Cycling, Handball

Introduction: My name is Fr. Dewey Fisher, I am a powerful, open, faithful, combative, spotless, faithful, fair person who loves writing and wants to share my knowledge and understanding with you.