Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to change Python path in reticulate

The first lines I run when launching my rstudio session are:

library(reticulate) use_python("/usr/local/lib/python3.6/site-packages") 

However, when I run py_config() it shows as still using the default python 2.7 installation.

This is an issue because I'm unable to import any modules that were installed for python3. Any idea why this isn't working? I followed documentation fairly closely.

like image 477
hackerman Avatar asked May 03 '18 01:05

hackerman


People also ask

How do I change the reticulate version of Python?

By setting the value of the RETICULATE_PYTHON environment variable to a Python binary. Note that if you set this environment variable, then the specified version of Python will always be used (i.e. this is prescriptive rather than advisory).

How do I change Python path in Linux?

Setting Path in Unix or LinuxIn the csh shell, type the following sentence: PATH “$PATH:/usr/local/bin/python” and press Enter. If you are using the standard flavour of Linux, open up the bash shell and type the following phrase, export PATH=”$PATH:/usr/local/bin/python” and press Enter.

Which Python does reticulate use?

library(reticulate) os <- import("os") os$listdir(".") Functions and other data within Python modules and classes can be accessed via the $ operator (analogous to the way you would interact with an R list, environment, or reference class). The reticulate package is compatible with all versions of Python >= 2.7.


1 Answers

I observed that neither the technique "use_python('path')" nor the tactic of Sys.setenv(RETICULATE_PYTHON = 'path') in .RProfile worked for me (of course I am sure it must have worked for others.)

In any case the line at terminal,

which -a python python3 

did produce two paths to choose from (one for python2 and one for python3 installed on my mac), so then I was able to create a ".Renviron" file in my home directory with this single line in it:

RETICULATE_PYTHON="/usr/local/bin/python3" 

After I restarted RStudio, library(reticulate) activates the desired python3, and repl_python() opens a python3 interactive window, etc. etc.

like image 63
George D Girton Avatar answered Sep 22 '22 19:09

George D Girton