use python 3 in Rstudio cloud

How can I use python 3 as the default python version in Rstudio cloud?
If I run:
reticulate::py_config()

I get the following:
python: /usr/bin/python
libpython: /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
pythonhome: /usr:/usr
version: 2.7.12 (default, Nov 12 2018, 14:36:49) [GCC 5.4.0 20160609]
numpy: [NOT FOUND]

python versions found:
/usr/bin/python
/usr/bin/python3

See info on Python Version Configuration with reticulate here:
https://rstudio.github.io/reticulate/articles/versions.html

Based on what you've shown above, it looks like use_python("/usr/bin/python3") should work.

I tried but nothing happens. Do you have an idea why?

I do not. I'm guessing someone else will, though. :crossed_fingers:

Reticulate does not work too well in the presence of multiple versions of Python, from what I understand. There are supposed to be improvements on the way, you might find them in the GitHub repository.

1 Like

the following code:
library(reticulate)
use_python("/usr/bin/python3")
py_discover_config()

returns this:
python: /usr/bin/python3
libpython: /usr/lib/libpython3.5.so[NOT FOUND]
pythonhome: /usr:/usr
version: 3.5.2 (default, Nov 12 2018, 13:43:14) [GCC 5.4.0 20160609]
numpy: [NOT FOUND]

python versions found:
/usr/bin/python3
/usr/bin/python

and Python in that case it does not work. Is there any other method different from reticulate to have python3 working in Rstudio cloud?

maybe for Rstudio cloud there is a different method for using python 3 instead of the version 2.7?

This method seems to work for me. Look here.

@Yarnabrina I cannot open your link, I get:
Sorry, but you do not have access.

Can you paste the code?

I'm not sure why you can't access it. I made sure that everyone can view the project.

Can you please try once again and check?

https://rstudio.cloud/spaces/11198/project/221645

Meanwhile, my notebook has the following:

---
title: "R Notebook"
output: html_notebook
---

```{r}
library(reticulate)
use_python("/usr/bin/python3")
```

```{python}
x = [5, 6, 7, 8]
for i, j in enumerate(x):
    print(i, 'th element of x is', j)
```

I still cannot open that project.

Anyway, when I run the following code:

```{r}
library(reticulate)
use_python("/usr/bin/python3")
```

```{python}
x = [5, 6, 7, 8]
for i, j in enumerate(x):
    print(i, 'th element of x is', j)
```

I get this:

Error in initialize_python(required_module, use_environment) :
Python shared library '/usr/lib/libpython3.5.so' not found, Python bindings not loaded.

I found similar issues on google but not specifically with Rstudio cloud, so I am wondering if there is a specific solution for Rstudio cloud

I believe this is happening because the system package libpython3-dev is not installed.
We will look into adding this in the next quarterly update of the base image.

1 Like

in this case, why for Yarnabrina it works and for me not?

I do not know. When I tried it, I experience your failure.

yes, I face the same issue with different projects

I created the following new project which has the same issue:
https://rstudio.cloud/project/224848
can you open it?

Yes, I can open it. So, I'm wondering what I did wrong so that you couldn't open mine. Can you please tell me what is your sharing settings?

Anyway, I failed to run the code chinks of Python3.Rmd at first. Then I tried to run py_config() and even that failed.

So, I just uninstalled reticulate and made a fresh install of it. After that, I can run it. Here's the screenshot:

I don't know whether you'll be able to see these changes directly or not. So, I'm making a copy into a new space and sharing the project link. Hopefully, you'll be able to access it. :crossed_fingers:

https://rstudio.cloud/spaces/11198/project/224905

I still cannot access to your shared projects.

Which version of reticulate did you install?
I removed and I installed again reticulate in the project: https://rstudio.cloud/project/224848
As you can see there, the version installed is 1.1 from CRAN
However, it is still not working.

Is it possible that somehow, your whole Rstudio cloud account has something different from the others?

I'm pretty sure it's not the case. Why? I just tried once again in the project that I derived from yours, and failed. Reinstalling didn't work this time.

I was trying to open a new project by myself, and failed. I got curious and noted that in all the previous projects (where I succeeded), I've installed keras there. When one installs keras, loads it and run install_keras(), which will do the following as per this documentation:

The Keras R interface uses the TensorFlow backend engine by default. To install both the core Keras library as well as the TensorFlow backend use the install_keras() function:

library(keras)
install_keras()

This will provide you with default CPU-based installations of Keras and TensorFlow.

Anyway, I noted that I succeeded to run the same code (which failed before installing keras). I don't why it's happening. Let me know whether this works for you as well or not.

And, someone please let me know the correct way to share a project. I created a new space named Other Space, changed access to Shared with initial role as Contributor and then shared the project link after changing Who can view this project to Everyone in Other Space, but enric can't access it. So, I must be missing something.