3

I'm using reticulate R package and want to configure python3 with it, however not able to do it. I tried the following code

library(reticulate)

packageVersion("reticulate")
# [1] ‘1.10.0.9002’

use_python(python = "/usr/bin/python", required = TRUE)

py_config()
# python:         /usr/bin/python
# libpython:      /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
# pythonhome:     /usr:/usr
# version:        2.7.15rc1 (default, Apr 15 2018, 21:51:34)  [GCC 7.3.0]
# numpy:          /usr/lib/python2.7/dist-packages/numpy
# numpy_version:  1.13.3
#
# NOTE: Python version was forced by use_python function

Sys.which("python3")
# python3 
# "/usr/bin/python3" 

use_python(python = "/usr/bin/python3", required = TRUE)

py_config()
# python:         /usr/bin/python
# libpython:      /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
# pythonhome:     /usr:/usr
# version:        2.7.15rc1 (default, Apr 15 2018, 21:51:34)  [GCC 7.3.0]
# numpy:          /usr/lib/python2.7/dist-packages/numpy
# numpy_version:  1.13.3
# 
# NOTE: Python version was forced by use_python function

Any hints, please.

MYaseen208
  • 22,666
  • 37
  • 165
  • 309
  • 1
    Use the `RETICULATE_PYTHON` environment variable set it as `RETICULATE_PYTHON=/usr/bin/python3` in your shell or in `~/.Renviron` and you won't need to do anything in your code to have R + `reticulate` default to `python3`. – hrbrmstr Sep 20 '18 at 08:13

1 Answers1

3

Do not run

use_python(python = "/usr/bin/python", required = TRUE)

before configuring into python3. As discussed here, only one python interpreter is allowed for an R session.

Here is what I saw on my laptop if use_python is only configured for python3:

library(reticulate)
use_python(python = Sys.which("python3"), required = TRUE)
py_config()

# python:         /usr/local/bin/python3
# libpython:      /usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/config-3.5m/libpython3.5.dylib
# pythonhome:     /usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5:/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5
# version:        3.5.2 (default, Jul 28 2016, 21:28:00)  [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]
# numpy:          /usr/local/lib/python3.5/site-packages/numpy
# numpy_version:  1.12.0
# 
# NOTE: Python version was forced by use_python function
mt1022
  • 16,834
  • 5
  • 48
  • 71