rstudiorpython

Environment variables and RStudio


I'm using RStudio and have been trying to use the rPython package to do some email handling for me. This involves unpacking some email attachments so I need to use a newer version of Python than 2.7.

I am on ubuntu so I've set environment variables in a bash script which I can see has worked:

bash

alias python=python3
export RPYTHON_PYTHON_VERSION=3

command line

echo $RPYTHON_PYTHON_VERSION
3

And yet, when I install rPython in RStudio it says:

Installing package into ‘/home/richardc/R/x86_64-pc-linux-gnu-library/3.1’ (as ‘lib’ is unspecified) trying URL 'http://cran.rstudio.com/src/contrib/rPython_0.0-5.tar.gz' Content type 'application/x-gzip' length 37109 bytes (36 Kb)

opened URL

downloaded 36 Kb

So, despite python --version returning 3.4 and setting the environment variable it is defaulting to 2.7

I'm hoping that there is something straightforward I'm missing.


Solution

  • @nickbloom was actually close to it, but it is not Sys.setenv(RPYTHON_PYTHON_PATH=3) but Sys.setenv(RPYTHON_PYTHON_VERSION=3)

    In my case (I have Python 3.5) it was:

    > Sys.setenv(RPYTHON_PYTHON_VERSION=3.5)  
    > install.packages('rPython')  
    Installing package into ‘/usr/lib64/R/library’ (as ‘lib’ is unspecified) trying URL  
    'http://r.meteo.uni.wroc.pl/src/contrib/rPython_0.0-5.tar.gz' Content  
    type 'application/x-gzip' length 37109 bytes (36 KB)  
    ================================================== downloaded 36 KB  
    
    * installing *source* package ‘rPython’ ...  
    ** package ‘rPython’ successfully unpacked and MD5 sums checked which: no python3.5-config in (/sbin:/bin:/usr/sbin:/usr/bin) could not  
    locate python3.5-config  
    

    As you can see now it is looking for python3.5-config, which is the version I specified above.

    Also if your python3.5-config file is not in the PATH then you might also want to set the PATH:

    Sys.setenv(PATH='/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin')
    

    You might also need to rename python3.5m-config, because rPython always looks for [pythoncommand]-config, which in my case was python3.5 and not python3.5m, so I just renamed python3.5m-config to python3.5-config and then the rPython package has installed.