RStudio Cloud will not use Python 3

Hello all - trying to set up a cloud environment for my students who can't seem to get python to play along with R. https://rstudio.cloud/project/724316

I am trying to install the packages for the course into an environment with Python3. Here's what I have tried:

> library(reticulate)
> py_discover_config()
python:         /cloud/project/r-reticulate/bin/python
libpython:      /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
pythonhome:     /usr:/usr
virtualenv:     /cloud/project/r-reticulate/bin/activate_this.py
version:        2.7.12 (default, Nov 12 2018, 14:36:49)  [GCC 5.4.0 20160609]
numpy:          /cloud/project/r-reticulate/local/lib/python2.7/site-packages/numpy
numpy_version:  1.16.5

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

Then I used: use_python("/usr/bin/python3", required = TRUE) - and py_config() to check it was the right version. It was version 3 - so I went and installed all the packages. These apparently went into a reticulate virtual environment based on Python2:

> use_python("/cloud/project/r-reticulate/bin/python")
> py_config()
python:         /cloud/project/r-reticulate/bin/python
libpython:      /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
pythonhome:     /usr:/usr
virtualenv:     /cloud/project/r-reticulate/bin/activate_this.py
version:        2.7.12 (default, Nov 12 2018, 14:36:49)  [GCC 5.4.0 20160609]
numpy:          /cloud/project/r-reticulate/local/lib/python2.7/site-packages/numpy
numpy_version:  1.16.5

python versions found: 
 /cloud/project/r-reticulate/bin/python
 /usr/bin/python
 /usr/bin/python3

So then I tried creating a separate environment that specifically used Python3: virtualenv_create("ANLY_Courses", python = "/usr/bin/python3")

> use_python("/cloud/project/ANLY_Courses/bin/python", required = TRUE)
> py_config()
python:         /cloud/project/ANLY_Courses/bin/python
libpython:      /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
pythonhome:     /usr:/usr
virtualenv:     /cloud/project/ANLY_Courses/bin/activate_this.py
version:        2.7.12 (default, Nov 12 2018, 14:36:49)  [GCC 5.4.0 20160609]
numpy:           [NOT FOUND]

NOTE: Python version was forced by use_python function

But clearly this still defaults to 2. Is there anything I can do here to make it use Python3?

Thanks!

I think this is not related to RStudio Cloud but to reticulate package, maybe related to this github issue. Have you tried installing the development version of reticulate?

I'll note I've had no issues with reticulate 1.13 on my computer using Python3 and creating virtual environments that use Python3 ... that was with anaconda though.

Here's the error I get when I try to install reticulate from github: (seems like it would take too much memory to compile from other errors I am seeing):

> install_github("rstudio/reticulate")
Downloading GitHub repo rstudio/reticulate@master
✔  checking for file ‘/tmp/RtmpDaHKt5/remotesf77b336ba/rstudio-reticulate-64f685a/DESCRIPTION’ ...
─  preparing ‘reticulate’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  checking for LF line-endings in source and make files and shell scripts
─  checking for empty or unneeded directories
─  building ‘reticulate_1.13.0-9004.tar.gz’
   
Installing package into ‘/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
* installing *source* package ‘reticulate’ ...
** using staged installation
** libs
g++ -std=gnu++11 -I"/opt/R/3.6.0/lib/R/include" -DNDEBUG  -I"/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I/usr/local/include  -fpic  -g -O2  -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++11 -I"/opt/R/3.6.0/lib/R/include" -DNDEBUG  -I"/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I/usr/local/include  -fpic  -g -O2  -c event_loop.cpp -o event_loop.o
g++ -std=gnu++11 -I"/opt/R/3.6.0/lib/R/include" -DNDEBUG  -I"/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I/usr/local/include  -fpic  -g -O2  -c libpython.cpp -o libpython.o
g++ -std=gnu++11 -I"/opt/R/3.6.0/lib/R/include" -DNDEBUG  -I"/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I/usr/local/include  -fpic  -g -O2  -c output.cpp -o output.o
g++ -std=gnu++11 -I"/opt/R/3.6.0/lib/R/include" -DNDEBUG  -I"/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/Rcpp/include" -I/usr/local/include  -fpic  -g -O2  -c python.cpp -o python.o
g++: internal compiler error: Killed (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
make: *** [python.o] Error 4
/opt/R/3.6.0/lib/R/etc/Makeconf:176: recipe for target 'python.o' failed
ERROR: compilation failed for package ‘reticulate’
* removing ‘/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/reticulate’
* restoring previous ‘/home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/reticulate’
Error: Failed to install 'reticulate' from GitHub:
  (converted from warning) installation of package ‘/tmp/RtmpDaHKt5/filef76cf5a9df/reticulate_1.13.0-9004.tar.gz’ had non-zero exit status

Unfortunately, I can't find the /usr/share/doc/gcc folder to share that information.

Update: I was able to download the reticulate github and build it using devtools. Then I uploaded that into the cloud environment and installed it from the .gz file. Now things appear to be working ok - when I did py_discover_config() it said there wasn't anything installed and asked if I wanted mini conda, so I installed that and went along my way with Python3.

Thanks for the help!

3 Likes

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

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