Install Python#
These instructions describe how to install Python on a Linux server. RStudio's professional products require multiple versions of Python. These instructions install Python appropriately from pre-compiled binaries.
Instructions for installing Python from source can be found here.
Install required dependencies#
These instructions use conda
, a package management utility, to install different versions of Python.
After installing Python, conda environments are NOT used by RStudio's professional products.
Terminal
$ sudo mkdir /opt/Python
$ sudo curl -fsSL -o /opt/Python/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ sudo chmod 755 /opt/Python/miniconda.sh
$ sudo /opt/Python/miniconda.sh -b -p /opt/Python/miniconda
Specify Python Version#
Terminal
$ export PYTHON_VERSION="3.7.7"
Download and install Python#
Terminal
sudo /opt/Python/miniconda/bin/conda create --quiet --yes \
--prefix /opt/Python/"${PYTHON_VERSION}" \
--channel conda-forge \
python="${PYTHON_VERSION}"
Verify Python installation#
Verify that Python is installed by running the following command:
Terminal
$ /opt/Python/"${PYTHON_VERSION}"/bin/python --version
(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 RStudio 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 for your PyPI mirror,
available in Package Manager on the "Setup" page of your PyPI repository.
(Optional) Install additional Python packages#
You can install additional Python packages into your Python environment by running a command such as:
Terminal
$ sudo /opt/Python/"${PYTHON_VERSION}"/bin/pip install altair beautifulsoup4 cloudpickle \
cython dask gensim keras matplotlib nltk numpy pandas pillow pyarrow \
requests scipy scikit-image scikit-learn scrapy seaborn spacy sqlalchemy \
statsmodels tensorflow xgboost
(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:
File: /etc/profile.d/python.sh
PATH=/opt/Python/"${PYTHON_VERSION}"/bin:$PATH
(Optional) Make Python available as a Jupyter Kernel#
On RStudio Server Pro you can make the version of Python installed available for use in Jupyter by running these commands:
Terminal
sudo /opt/Python/${PYTHON_VERSION}/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 the installation steps using a different value for PYTHON_VERSION
. You
do not need to reinstall the conda utility which is a pre-requisite.
For example, you can run the following commands to install Python 2.7.16:
Terminal:
export PYTHON_VERSION="2.7.16"
sudo /opt/Python/miniconda/bin/conda create --quiet --yes \
--prefix /opt/Python/"${PYTHON_VERSION}" \
--channel conda-forge \
python="${PYTHON_VERSION}"