Installing\Uninstalling\Upgrading Python Modules in Linux using Pip

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.

Our Linux lab-image only supports Python 2.7, packages that require Python 3.0+ will not work with Pip

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 window.
  2. To install a package, use the command `pip install --user <package-name>`
    1. In this example: `pip install --user flask`
    2. This will import the flask package and its dependencies if it has any. Installing with Pip

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>`
    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 the Enter key. Uninstall using Pip

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 window.
  2. To upgrade a package, use the command `pip install --upgrade --user <package-name>`
    NOTE:
    • You will be unable to upgrade packages installed locally on the system.
    • You will be unable to upgrade packages that require newer versions of Python. We support Python 2.7 on our Linux lab-image, anything requiring Python 3.0+ will throw an error.
  3. Pip will automatically install packages for Python version 2.7, or below without the upgrade flag.
  4. This example will upgrade the numpy package
    Upgrading using Pip

Location of installed Python packages through Pip

By default Python packages installed through pip using the `--user` flag will be stored in the following home directory:
~/.local/lib/python2.7/site-packages
~ is your home directory location

Pip Location User
By default Python packages installed locally on each system will be stored in the following directory:
/usr/lib/python2.7/site-packages

Pip Location System

Was this helpful?
0 reviews

Details

Article ID: 66715
Created
Tue 11/6/18 9:58 AM
Modified
Fri 2/8/19 9:28 AM