I have installed Python 3.7 in the default location for High Sierra using the official OSX package downloaded from the official Python site. When I run
which python3
I get the path
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
I then run the following lines in R Studio
reticulate::use_python(python = '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3')
sys <- import("sys")
sys$version
It seems that I am still pointing to the default installation of 2.7
[1] "2.7.10 (default, Oct 6 2017, 22:29:07) \n[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]"
I tried many other paths such as
/usr/local/bin/python3
/usr/local/bin
/Library/Frameworks/Python.framework/Versions/3.7/lib
/usr/bin/python
/Applications/Python 3.7
etc., but none seems to work. (it still shows 2.7.10)
Obviously, I have tried googling for the solution but to no avail unfortunately. Any guidance would be greatly appreciated.
Update: I finally got it to work by:
- Restarting the R Session as recommended by serv-inc
Running the following commands:
library(reticulate) reticulate::use_python(python = '/Library/Frameworks/Python.framework/Versions/3.7/bin/python3', required = T) sys <- import("sys") sys$version
to get the following response:
[1] "3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) \n[Clang 6.0 (clang-600.0.57)]"
If I have incorrectly specified an incorrect path such as
/usr/bin/python
, I would need to restart the R session or else reticulate would continue referring to the existing Python version.
In short, the problem was caused by the incorrect path specified in the initial call to the reticulate::use_python
function, and subsequent calls with the correct path would not take effect as it requires a 'fresh' R session.