Using pip3 to install Python3 modules

 

Overview

This article explains how to use pip3 to install Python modules.

To run the following commands, you must log in to your server via SSH with your Shell user. View the following articles for more information:

How to use pip3

Before you install any modules, you need to make sure that pip3 is installed. The following sections provide more information about how to install, activate, and upgrade pip3.

Installing

When you use a custom version of Python 3, pip3 is already installed. You can visit this page if you need to find additional ways to install it separately.

Activating

After it's installed, run the following to activate your local Python environment:

[server]$ . ~/.bash_profile

You now have access to pip3. Confirm this by running the following:

[server]$ pip3 --version
pip 18.1 from /home/username/opt/python-3.6.2/lib/python3.6/site-packages/pip (python 3.6)

Upgrading

At this point, it's a good idea to upgrade pip3. You can upgrade it by running the following:

[server]$ python3 -m pip install --upgrade pip

[server]$ pip3 --version pip 18.1 from /home/username/opt/python-3.6.2/lib/python3.6/site-packages/pip (python 3.6)

Installing modules

When working with Python projects, it's recommended to create a virtual environment. This allows you to create an isolated environment, separate from the system version of Python. Any changes you make to this virtual environment only affect the single project and nothing else. In this way, it's a very safe way to test your projects, as they can be deleted and rebuilt very easily. See this article for further details.

Installing a virtual environment is important if you want to run pip. Normally, pip attempts to install in the server's default Python system folder. This does not work since you do not have access to this folder. When you create a virtual environment, pip installs locally under your user, so you'll be able to install anything you like without any errors occurring.

To use pip3 to easily install custom modules:

  1. Install a custom version of Python3 and create a virtual environment.
  2. Make sure you're in the same directory as the virtual environment you created.
  3. Run the following command to activate this new virtual environment.

    Make sure to change the directory to where you installed it. The following example assumes the name of your virtual environment is venv.

    [server]$ source venv/bin/activate

    The name of the current virtual environment appears to the left of the prompt. For example:

    (venv) [server]$ 
  4. Use pip3 to install a module:
    (venv) [server]$ pip3 install module
    For example, you can use python-openstackclient if you're going to work with Openstack.
    (venv) [server]$ pip3 install python-openstackclient

View the following links for further module examples:

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?