Using pip3 to install Python3 modules

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

Installing pip3

To use pip3, first install a custom version of Python 3. pip3 is then installed with it.

Using pip3

Once 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 pip3

At this point, it's a good idea to upgrade pip3.

[server]$  python3 -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 613kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.1
    Uninstalling pip-9.0.1:
      Successfully uninstalled pip-9.0.1
Successfully installed pip-18.1
[server]$ pip3 --version pip 18.1 from /home/username/opt/python-3.6.2/lib/python3.6/site-packages/pip (python 3.6)

Installing custom modules within your virtual environment

When working with Python projects, it's always a good idea 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 affects the single project, nothing else. In this way, it's a very safe way to test your projects as they can be deleted and rebuilt very easily. View the following article for further details.

Installing a virtualenv 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 error.

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. This 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?