Environment variables and RStudio

2.6k Views Asked by At

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

  • installing source package ‘rPython’ ... ** package ‘rPython’ successfully unpacked and MD5 sums checked a specific python version to use was not provided defaulting to the standard python in the system

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.

3

There are 3 best solutions below

0
On BEST ANSWER

@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.

0
On

In my case, none of the provided answers worked. I suspect it's because I installed python3 through homebrew (I'm on Mac OSX). However, this worked:

I edited the configure.ac file in the downloaded package and then installed it through R CMD INSTALL.

MYPYTHONCONFIG=python3-config
MYPYTHON=python3
2
On

I know this is way late, but I believe you have to set the R environment variable, not the bash environment variable. Set it like this: Sys.setenv(RPYTHON_PYTHON_PATH=3)

HTH.

EDIT: Nope, that's not it. I'm stumped, too.