Install Python#
These instructions describe how to install Python on a Linux server. Posit professional products require multiple versions of Python. These instructions install Python appropriately from pre-compiled binaries.
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
$ 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"
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:
$ sudo subscription-manager repos --enable "rhel-*-optional-rpms"
# Optional repository from Red Hat Update Infrastructure (RHUI)
$ sudo yum install yum-utils
$ sudo yum-config-manager --enable "rhel-*-optional-rpms"
$ sudo apt-get update
$ sudo apt-get install gdebi-core
Specify Python Version#
$ export PYTHON_VERSION="3.9.14"
Available versions of Python
Versions of Python that are available include:
3.7.0, 3.7.1, 3.7.2, 3.7.3, 3.7.4, 3.7.5, 3.7.6, 3.7.7, 3.7.8, 3.7.9, 3.7.10, 3.7.11, 3.7.12, 3.7.13, 3.7.14, 3.7.15
3.8.0, 3.8.1, 3.8.2, 3.8.3, 3.8.4, 3.8.5, 3.8.6, 3.8.7, 3.8.8, 3.8.9, 3.8.10, 3.8.11, 3.8.12, 3.8.13, 3.8.14, 3.8.15
3.9.0, 3.9.1, 3.9.2, 3.9.3, 3.9.4, 3.9.5, 3.9.6, 3.9.7, 3.9.8, 3.9.9 3.9.10, 3.9.11, 3.9.12, 3.9.13, 3.9.14, 3.9.15
3.10.0, 3.10.1, 3.10.2, 3.10.3, 3.10.4, 3.10.5, 3.10.6, 3.10.7, 3.10.8
3.11.0, 3.11.1, 3.11.2, 3.11.3
If you need to use an earlier version of Python, then you will need to modify the export command shown above:
$ export PYTHON_VERSION=3.X.X
Please see the Python downloads page for all available versions of Python.
Python versions greater than 3.9.14, 3.10.X, and 3.11.X are currently unavailable for RHEL/CentOS 7.
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/centos-7/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-2204/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
$ sudo gdebi python-${PYTHON_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/python/ubuntu-2004/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
$ sudo gdebi python-${PYTHON_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/python/ubuntu-1804/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
$ sudo gdebi python-${PYTHON_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/python/debian-11/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
$ sudo gdebi python-${PYTHON_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/python/debian-10/pkgs/python-${PYTHON_VERSION}_1_amd64.deb
$ sudo gdebi python-${PYTHON_VERSION}_1_amd64.deb
$ curl -O https://cdn.rstudio.com/python/opensuse-154/pkgs/python-${PYTHON_VERSION}-1-1.x86_64.rpm
$ sudo zypper --no-gpg-checks install python-${PYTHON_VERSION}-1-1.x86_64.rpm
$ curl -O https://cdn.rstudio.com/python/opensuse-153/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#
Connect requires that users have updated versions of some built-in Python tools. To upgrade the required tools, run the following command:
$ /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:
[global]
index-url = https://example.company.com/pypi/latest
Replace https://example.company.com/pypi/latest
with the URL for your PyPI mirror, available in Package Manager on the "Setup" page of your PyPI repository.
(Optional) Add Python to the system PATH#
Info
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, this can be defined in a script within the /etc/profile.d/
directory:
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) 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.
Note
The minimum Python version supported by Connect is now 3.7. Configuration files that include Python 2, or Python 3 versions prior to 3.7, 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.