Install Python
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:
sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms
# enable the CodeReady Linux Builder repository from Red Hat Update Infrastructure (RHUI)
sudo dnf install dnf-plugins-core
sudo dnf config-manager --set-enabled codeready-builder-for-rhel-9-*-rpms
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:
sudo subscription-manager repos --enable codeready-builder-for-rhel-8-x86_64-rpms
# enable the CodeReady Linux Builder repository from Red Hat Update Infrastructure (RHUI)
sudo dnf install dnf-plugins-core
sudo dnf config-manager --set-enabled "codeready-builder-for-rhel-8-*-rpms"
Specify the Python version
Consult with your Python user group to determine which version/versions of Python they would like installed. Once defined, set the environment variable, shown below, to the first Python version they request.
export PYTHON_VERSION="3.12.4"
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.
curl -O https://cdn.rstudio.com/python/rhel-9/pkgs/python-${PYTHON_VERSION}-1-1.x86_64.rpm
sudo yum install python-${PYTHON_VERSION}-1-1.x86_64.rpm
curl -O https://cdn.rstudio.com/python/centos-8/pkgs/python-${PYTHON_VERSION}-1-1.x86_64.rpm
sudo yum install python-${PYTHON_VERSION}-1-1.x86_64.rpm
curl -O https://cdn.rstudio.com/python/ubuntu-2404/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
sudo apt-get update
sudo apt-get install ./python-${PYTHON_VERSION}_1_amd64.deb
curl -O https://cdn.rstudio.com/python/ubuntu-2204/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
sudo apt-get update
sudo apt-get install ./python-${PYTHON_VERSION}_1_amd64.deb
curl -O https://cdn.rstudio.com/python/ubuntu-2004/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
sudo apt-get update
sudo apt-get install ./python-${PYTHON_VERSION}_1_amd64.deb
curl -O https://cdn.rstudio.com/python/debian-12/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
sudo apt-get update
sudo apt-get install ./python-${PYTHON_VERSION}_1_amd64.deb
curl -O https://cdn.rstudio.com/python/debian-11/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
sudo apt-get update
sudo apt-get install ./python-${PYTHON_VERSION}_1_amd64.deb
curl -O https://cdn.rstudio.com/python/debian-10/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
sudo apt-get update
sudo apt-get install ./python-${PYTHON_VERSION}_1_amd64.deb
curl -O https://cdn.rstudio.com/python/opensuse-155/pkgs/python-${PYTHON_VERSION}-1-1.x86_64.rpm
sudo zypper --no-gpg-checks install python-${PYTHON_VERSION}-1-1.x86_64.rpm
Verify Python installation
Verify that Python is installed by running the following command:
/opt/python/"${PYTHON_VERSION}"/bin/python --version
Upgrade required Python tools
When installing Python on a Posit Connect server, each Python installation is required to have the pip
, venv
, and setuptools
packages installed. The Python venv
module is used to create content-specific environments, while pip
and setuptools
are used to install Python packages.
When using Python >= 3.12
, the setuptools
module is no longer installed by default.
Connect requires that users have updated versions of these Python tools. To install and 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
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:
cat << EOF | sudo tee /etc/profile.d/python.sh
#!/bin/bash
export PATH=/opt/python/${PYTHON_VERSION}/bin:\$PATH
EOF
(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) 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.
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.