Install Python

These instructions describe how to install Python from Anaconda on a Linux server.

Install required dependencies

Use the following commands to install the dependencies required to install Python for your Linux distribution.

$ sudo yum install bzip2
$ sudo apt-get install bzip2
$ sudo zypper install bzip2

Download and install Python

Download and install Python 3.6.5 by running the following commands:

Terminal

$ curl -O https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
$ sudo bash Anaconda3-5.2.0-Linux-x86_64.sh -bp /opt/python/3.6.5/

Info

The above command will install Python 3.6.5, which is the default version of Python available in the version of that installer. You can download and install a different version of Python by using another version of the Anaconda installer, or by creating a new Python environment with a different version of Python.

Verify Python installation

Verify that Python is installed by running the following command:

Terminal

$ /opt/python/3.6.5/bin/python --version

(Optional) Install additional Python packages

You can install additional Python packages into the your Python environment by running a command such as:

Terminal

$ sudo /opt/python/3.6.5/bin/pip install virtualenv pandas matplotlib

(Optional) Add Python to the system PATH

Info

You can configure Python on the system PATH so that users will be able to use pip within a terminal to install packages to their home directory, similar to how R works with install.packages().

The recommended method to add Python to the PATH is to append the version of Python that you installed to the system-wide PATH variable. For example, this can be defined in a script within the /etc/profile.d/ directory:

File: /etc/profile.d/python.sh

PATH=/opt/python/<PYTHON_VERSION>/bin:$PATH

where <PYTHON-VERSION> is the version of Python that you installed earlier.

(Optional) Install multiple versions of Python

If you want to install multiple versions of Python on the same server, you can repeat these steps to specify, download, and install a different version of Python alongside existing versions to other locations.

For example, you can run the following commands to install Python 2.7.16:

$ curl -O https://repo.anaconda.com/archive/Anaconda2-2019.07-Linux-x86_64.sh
$ sudo bash Anaconda2-2019.07-Linux-x86_64.sh -bp /opt/python/2.7.16/

Or, you can run the following commands to install Python 3.7.3:

$ curl -O https://repo.anaconda.com/archive/Anaconda3-2019.07-Linux-x86_64.sh
$ sudo bash Anaconda3-2019.07-Linux-x86_64.sh -bp /opt/python/3.7.3/