pip – system-wide Python-based installation of PyCUDA

For a system-wide installation of PyCUDA tied to your existing Python base, we first have to install pip, which is a tool for installing Python packages.

To install Pip for Python 3.x, use the following command:

sudo apt install python3-pip

pip for Python 2.x can be installed via the following:

sudo apt install python-pip

Here is an important note from the developers of pip:

Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.

It is recommended to use/transition to Python 3.x to work on Python-based packages or to develop new Python software to future-proof GPU support.

Coming back to our system-wide PyCUDA installation, the Python 3.x version can be installed with the following commands on a terminal:

$ pip3 install --upgrade pip
$ pip3 install --user pycuda

Note that pip install --user pycuda also performs the same operation as pip3 install --user pycuda.

The alternative commands for installing PyCUDA for Python 2.x would be this:

$ pip2 install --upgrade pip
$ pip2 install --user pycuda

Now you have a user-specified configuration ready for use system-wide on your Ubuntu Linux system. In the next section, we'll learn how to configure both Conda-based and user-specified system-wide configurations on the PyCharm IDE.