[英]Trouble loading Python in RStudio with reticulate
I am trying to run a R Markdown document which uses both R and Python code chunks.我正在尝试运行同时使用 R 和 Python 代码块的 R Markdown 文档。 I am on macOS Catalina version 10.15.2, R version is 3.6.2 and RStudio version is 1.2.5033.
我使用的是 macOS Catalina 版本 10.15.2,R 版本是 3.6.2,RStudio 版本是 1.2.5033。 I am using the
reticulate
package version 1.14.我正在使用
reticulate
包版本 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
.终端上的
which python
显示/Users/dhirajkhanna/opt/anaconda3/bin/python
并且在我的.Renviron
文件中输入相同的 RETICULATE_PYTHON 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.奇怪的是,当我在我的 RStudio 控制台中执行
Sys.which('python')
时,它向我显示了一条不同的路径,即。 /usr/bin/python
. /usr/bin/python
。 When I load the reticulate
package, the output of py_config()
is:当我加载
reticulate
包时, py_config()
的输出是:
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:
/usr/bin/python3
/usr/local/bin/python3
/usr/bin/python
/usr/local/bin/python
/Users/dhirajkhanna/anaconda3/bin/python
/Users/dhirajkhanna/.virtualenvs/object_recognition_detection/bin/python
/Users/dhirajkhanna/.virtualenvs/object_recognition_detection1/bin/python
/Users/dhirajkhanna/.virtualenvs/r-tensorflow/bin/python
/Users/dhirajkhanna/venv/bin/python
If I specify, use_python('/Users/dhirajkhanna/opt/anaconda3/bin/python')
, the output of py_config()
is:如果我指定
use_python('/Users/dhirajkhanna/opt/anaconda3/bin/python')
, py_config()
的输出是:
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:
/Users/dhirajkhanna/opt/anaconda3/bin/python
/usr/bin/python3
/usr/local/bin/python3
/usr/bin/python
/usr/local/bin/python
/Users/dhirajkhanna/anaconda3/bin/python
/Users/dhirajkhanna/.virtualenvs/object_recognition_detection/bin/python
/Users/dhirajkhanna/.virtualenvs/object_recognition_detection1/bin/python
/Users/dhirajkhanna/.virtualenvs/r-tensorflow/bin/python
/Users/dhirajkhanna/venv/bin/python
Now when I try to load Python packages in a Python code chunk, RStudio crashes:现在,当我尝试在 Python 代码块中加载 Python 包时,RStudio 崩溃了:
import pandas as pd
import matplotlib.pyplot as plt
I get the "R Session Aborted" message.我收到“R Session Aborted”消息。 All this was working fine till I upgraded R. Any idea how to rectify this?
在我升级 R 之前,所有这些都工作正常。知道如何纠正这个问题吗?
Edit编辑
While trying this in R, I get a segmentation error:在 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'
Traceback:
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
Selection:
I have also tried running a different version of Python (3.6) in a virtualenv but still no joy.我也尝试过在 virtualenv 中运行不同版本的 Python (3.6),但仍然没有任何乐趣。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.