在 R 中导入 python 模块

Importing python module in R

我正在尝试使用 reticulate 包在 R 中导入一个 python 模块。可以找到该模块 here。我成功克隆了存储库和 运行 python setup.py install 运行。如果我打开 python shell,我可以导入 debot。但是,当我尝试在 RStudio 中导入它时,出现以下错误:

dbot=import("debot")
Error in py_module_import(module, convert = convert) : 
  ImportError: No module named debot

我使用的是 macOS Sierra 版本 10.12.6,并通过 Anaconda 安装了 python 3.6。我还尝试将 python 的路径指定为:

path_to_python <- "/anaconda/bin/python3.6"
use_python(path_to_python)

当我从终端 运行 python 时,我得到:

Python 3.6.1 |Anaconda 4.4.0 (x86_64)| (default, May 11 2017, 13:04:09) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

不确定 python 的路径是否正确。

好吧,做了更多的挖掘,发现 reticulate 仍然指的是我的 python 2.7 的旧 python 路径,它是我的 Macbook 的默认路径。当我 运行 py_config() 时,这是我得到的:

python:         /usr/bin/python
libpython:      /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome:     /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version:        2.7.10 (default, Feb  7 2017, 00:08:15)  [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]

无论我尝试什么,但我无法reticulate查看使用use_python()函数安装模块的正确路径。我相信这是 reticulate 的问题。知道我接下来应该做什么吗?

看了this终于明白了。我认为在调用 reticulate 包中的任何其他函数之前,必须指定要使用的 python 的路径。因此,我现在遵循的顺序是:

library(reticulate)
path_to_python <- "/anaconda/bin/python"
use_python(path_to_python)