Install Python

How to install Python on a Linux server appropriately from pre-compiled binaries.

Posit professional products require multiple versions of Python.

Install required dependencies

To install the necessary runtime dependencies for Python, you must enable additional repositories for third-party or source packages by using the following commands:

Enable the Extra Packages for Enterprise Linux (EPEL) repository:

sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

Enable the CodeReady Linux Builder repository:

Enable the Extra Packages for Enterprise Linux (EPEL) repository

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Enable the CodeReady Linux Builder repository:

Enable the Extra Packages for Enterprise Linux (EPEL) repository

sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 

Enable the Optional repository:

Specify the Python version

export PYTHON_VERSION="3.11.9"

Versions of Python that are available include: 3.8.x ,3.9.x, 3.10.x, 3.11.x, 3.12.x

If you need to use an earlier version of Python, then you will need to modify the export command shown above:

Terminal
export PYTHON_VERSION=3.X.X

Please see the Python downloads page for all available versions of Python.

Download and install Python

Download and install the desired version of Python.

Verify Python installation

Verify that Python is installed by running the following command:

/opt/python/"${PYTHON_VERSION}"/bin/python --version

Upgrade required Python tools

Connect requires that users have updated versions of some built-in Python tools. To upgrade the required tools, run the following command:

sudo /opt/python/"${PYTHON_VERSION}"/bin/pip install --upgrade \
    pip setuptools wheel

(Optional) Configure a PyPI repository

You can specify a default PyPI mirror for all installations of Python by creating a pip configuration file. This can be useful if you are using an internal PyPI mirror such as Posit Package Manager:

To do so, create a file located at /etc/pip.conf containing:

File: /etc/pip.conf
[global]
index-url = https://example.company.com/pypi/latest

Replace https://example.company.com/pypi/latest with the URL of your PyPI mirror, available in Package Manager on the Setup page of your PyPI repository.

(Optional) Add Python to the system PATH

Note

You can configure Python on the system PATH so that users can 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, define this in a script within the /etc/profile.d/ directory:

File: /etc/profile.d/python.sh
PATH=/opt/python/"${PYTHON_VERSION}"/bin:$PATH

(Optional) Make Python available as a Jupyter Kernel

For Workbench, you can make the version of Python installed available for use in Jupyter by running these commands:

sudo /opt/python/${PYTHON_VERSION}/bin/pip install ipykernel
sudo /opt/python/${PYTHON_VERSION}/bin/python -m ipykernel install --name py${PYTHON_VERSION} --display-name "Python ${PYTHON_VERSION}"

(Optional) Configure Python local Certificate Authority trust

Add the root CA certificate to the system trust store for Python on Workbench to trust internally generated certificates. See the Posit Team SSL Considerations support article for more information. Then, point the environment variable REQUESTS_CA_BUNDLE to the Linux system certificate store you have just updated based on the article above. You can set REQUESTS_CA_BUNDLE to the appropriate certificate bundle by updating the /etc/rstudio/launcher-env on Posit Workbench like this:

JobType: any
Workbench: any
Environment: REQUESTS_CA_BUNDLE=/etc/pki/ca-trust/extracted/tls-ca-bundle.pem
JobType: any
Workbench: any
Environment: REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt

For Posit Connect, use a program supervisor script to set REQUESTS_CA_BUNDLE for all applications and content that run in Connect. The Environment variables on Posit Connect article provides an example of this workflow.

(Optional) Install multiple versions of Python

To install multiple versions of Python on the same server, repeat these steps to specify, download, and install a different version of Python alongside existing versions.

Note

Use Connect’s System Requirements - Runtime support documentation to confirm the minimum Python version supported by Connect. Configuration files that include Python 3 versions lower than the minimum supported version cause an error during Connect startup.

Additional information

Refer to the rstudio/python-builds repository on GitHub for more information on these binary distributions of Python.

Follow these steps to install Python from source.

Back to top