Python & RStudio Server

Hi,

What are the best pratices to install and configure Python for RStudio Server Pro cluster ?

I found the documentation about RStudio Connect
https://docs.rstudio.com/connect/admin/python.html

But nothing similar for rstudio server.

The clever way seems to follow the same recommendation about building python from source.

if anyone is willing to share experience, feel free!

Idea for RStudio Team :
adding mention and reference in the admin doc for rstudio server about Python installation could be useful.

Thanks a lot everyone !

2 Likes

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:

  1. 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
  2. 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
  3. 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:

  1. 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
  2. Each user will create a virtualenv using a command like: /opt/Python/3.6.8/bin/virtualenv ~/python
  3. User can install packages in their virtualenv using ~/python/bin/pip install pandas matplotlib and so on
  4. 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
  5. User can now develop Shiny apps, R Markdown, and Plumber APIs with Python/R in RSP using the reticulate library per RStudio 1.2 Preview: Reticulated Python - Posit and Interface to Python • 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:

3 Likes

Thanks a lot ! That is a great overview and perfect guidelines.

I would like to find a way to not explain to every user that they have to configure themselves their python setup, but I may offer them specific install function like usethis to help setting things up with reticulate.

On the R side, having on site-library already configured globally help greatly reduce the "admin-like-stuff" for the majority of the user. I would like the experience with python the same: one global configuration that works for everyone, and the choice for advanced user to go further and setup their session more precisely.

I follow the https://solutions.rstudio.com/ website. having a RSS feed or a way to know that there is new article would really help. There is such feature on support.rstudio.com with article, and it is very useful being able to register for email notification. :blush:
Don't know what is possible with your template.

Thanks again.

Yes, you can definitely optimize the steps that I outlined via usethis and installing more site-wide packages. You can consider the steps that I outlined a minimal/basic starting point. And we'll continue to optimize those steps based on user feedback like yours!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

To follow up on this topic, I published some updates to the RStudio Solutions site that collect all of our resources for using Python with RStudio:

https://solutions.rstudio.com/python/overview/

https://solutions.rstudio.com/python/configure/

And a new support article on configuring Python with RStudio Server Pro and RStudio Connect:

1 Like