Trouble loading Python in RStudio with reticulate

I am trying to run a R Markdown document which uses both R and Python code chunks. I am on macOS Catalina version 10.15.2, R version is 3.6.2 and RStudio version is 1.2.5033. I am using the reticulate package version 1.14.

which python on the Terminal reveals /Users/dhirajkhanna/opt/anaconda3/bin/python and the same is entered in my .Renviron file as RETICULATE_PYTHON=/Users/dhirajkhanna/opt/anaconda3/bin/python . Strangely when I do Sys.which('python') in my RStudio console, it shows me a different path, viz. /usr/bin/python . When I load the reticulate package, the output of py_config() is:

python:         /usr/local/bin/python3
libpython:      /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7.dylib
pythonhome:     /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7:/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7
version:        3.7.4 (default, Jul  9 2019, 18:13:23)  [Clang 10.0.1 (clang-1001.0.46.4)]
numpy:          /usr/local/lib/python3.7/site-packages/numpy
numpy_version:  1.16.4

python versions found: 

If I specify, use_python('/Users/dhirajkhanna/opt/anaconda3/bin/python') , the output of py_config() is:

python:         /Users/dhirajkhanna/opt/anaconda3/bin/python
libpython:      /Users/dhirajkhanna/opt/anaconda3/lib/libpython3.7m.dylib
pythonhome:     /Users/dhirajkhanna/opt/anaconda3:/Users/dhirajkhanna/opt/anaconda3
version:        3.7.5 (default, Oct 25 2019, 10:52:18)  [Clang 4.0.1 (tags/RELEASE_401/final)]
numpy:          /Users/dhirajkhanna/opt/anaconda3/lib/python3.7/site-packages/numpy
numpy_version:  1.17.3

python versions found: 

Now when I try to load Python packages in a Python code chunk, RStudio crashes:

import pandas as pd
import matplotlib.pyplot as plt

I get the "R Session Aborted" message. All this was working fine till I upgraded R. Any idea how to rectify this?

In case it helps, RStudio crashes as soon as I insert a python code chunk in the R Markdown file and start typing some code there. I don't have to execute the code chunk for RStudio to crash.

I am getting a segmentation fault while trying to run this in R:

> library(reticulate)
> repl_python()
Python 3.7.6 (/Users/dhirajkhanna/opt/anaconda3/bin/python)
Reticulate 1.14 REPL -- A Python interpreter in R.
>>> import pandas as pd

 *** caught segfault ***
address 0x0, cause 'memory not mapped'

 1: py_eval_impl(code, convert)
 2: py_eval("_", convert = FALSE)
 3: doTryCatch(return(expr), name, parentenv, handler)
 4: tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5: tryCatchList(expr, classes, parentenv, handlers)
 6: tryCatch(py_eval("_", convert = FALSE), error = function(e) r_to_py(NULL))
 7: py_last_value()
 8: py_compile_eval(code)
 9: doTryCatch(return(expr), name, parentenv, handler)
10: tryCatchOne(expr, names, parentenv, handlers[[1L]])
11: tryCatchList(expr, classes, parentenv, handlers)
12: tryCatch(py_compile_eval(code), error = handle_error)
13: repl()
14: repl_python()

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.