The best approach for using Python with RStudio Server Pro (RSP) is to install Python from source for the same reasons we recommend this approach for R versions. This way, you can manage multiple versions of Python and decouple it from the system versions of Python.
The difference between using Python with RSP vs. RStudio Connect (RSC) is that for RSP, each user can create a virtual environment with Python to perform development work, whereas RSC will use the service account (default rstudio-connect) to automatically create virtual environments in Python for each application that is deployed.
This means that the process for installing Python with RSC (for app publishing) looks like:
- Install Python from source (one or more desired versions) following the steps here, including pip and virtualenv: https://docs.rstudio.com/connect/admin/python.html#python-install
- Enable Python support in the RSC configuration to point to the versions of Python that were installed: https://docs.rstudio.com/connect/admin/python.html#enabling-python-support
- Python/R apps deployed to RSC will use these base Python installations and create a virtualenv with the required Python packages at deployment time
Whereas the process for installing Python with RSP (for app development) looks like:
- Install Python from source (one or more desired versions) following the steps here, including pip and virtualenv: https://docs.rstudio.com/connect/admin/python.html#python-install
- Each user will create a virtualenv using a command like:
/opt/Python/3.6.8/bin/virtualenv ~/python
- User can install packages in their virtualenv using
~/python/bin/pip install pandas matplotlib
and so on
- Each user will configure the
RETICULATE_PYTHON
environment variable to point to the Python executable in their virtualenv, I recommend using either ~/.Rprofile
or ~/.Renviron
to set this
- User can now develop Shiny apps, R Markdown, and Plumber APIs with Python/R in RSP using the reticulate library per https://blog.rstudio.com/2018/10/09/rstudio-1-2-preview-reticulated-python/ and https://rstudio.github.io/reticulate/
Thanks for bringing up this question, as we are working on additional articles and assets around using Python with RSP and RSC, which we will summarize on https://solutions.rstudio.com/ when that information is ready.
In the mean time, we have some of this information documented here: