How to Change Python Path in Reticulate

How to properly set the Python path for the reticulate package in OSX High Sierra?

See https://github.com/rstudio/reticulate/issues/45:

Do

library("reticulate")
use_python("/usr/bin/python", required = T)

Before anything else.

See also https://github.com/rstudio/reticulate/issues/227:

reticulate will always prefer a version of Python that includes NumPy to one that doesn't. Does the version at /usr/local/bin/python3 have NumPy?



Obviously, I have tried googling for the solution

Sometimes, googling only the function name "reticulate::use_python" helps.

How to change the default python version/path in Rstudio

OK, so I have posted too early - after some more googling I can solve this problem myself, but I think it is worth posting an answer here for people like me (i.e. not path-proficient or python-proficient).

There is something like a config file for R, called .Renviron. In order to access it, use Terminal to go to your home directory (i.e. the one that you go to when you type 'cd'). If you have never used this file before, it might not exist, in which case you need to create it.

Once in your home directory, type:

ls -a

then check on the list of files that appears whether .Renviron is there. Below are instructions what if you already have .Renviron (IF YES), and what if you don't (IF NO).

IF NO, type:

touch .Renviron

which creates the file.

IF YES, just proceed as below (without using the touch command).

Write:

nano .Renviron

the .Renviron file will open. In it, add a line that says:

RETICULATE_PYTHON="enter your desired path here"

so, in my case, this is:

RETICULATE_PYTHON="/Library/Frameworks/Python.framework/Versions/3.7/bin/python3"

now save the file by exiting nano (ctrl+x) and clicking 'y' when it asks whether to save changes (press 'y' then press enter).

restart you RStudio. It should work now. I hope this is useful!

Using system-wide python via reticulate

The following fixes the problem:

Sys.setenv(RETICULATE_PYTHON = "/home/x/.virtualenvs/r.reticulate/bin/python")
library(reticulate)


Related Topics



Leave a reply



Submit