ModuleNotFoundError: No module named 'rpytools

2019-06-07 02:26发布

Hi this is my first stackoverflow question so sorry in advance for any mistakes. I am trying to start playing with R reticulate library. I have installed the package, and tried to import os Python module. Everything seemed to be ok, but then while I start typing for example os$listdir R throws this error: Error in py_module_import(module, convert = convert) : ModuleNotFoundError: No module named 'rpytools'. Here is my entire code:

install.packages("reticulate")
library(reticulate)
os <- import("os")
os$listdir("")

Here is my output of py_config() :

python:         C:\PROGRA~3\ANACON~1\python.exe
libpython:      C:/PROGRA~3/ANACON~1/python36.dll
pythonhome:     C:\PROGRA~3\ANACON~1
version:        3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)]
Architecture:   64bit
numpy:          C:\PROGRA~3\ANACON~1\lib\site-packages\numpy
numpy_version:  1.12.1
os:             C:\PROGRA~3\ANACON~1\lib\os.py

and py_available(TRUE) returns TRUE...

Please write me if there is any additional info needed.

标签: r reticulate
1条回答
在下西门庆
2楼-- · 2019-06-07 02:32

The short answer is you need to use RStudio version 1.2 or higher, currently only available as a preview release, to get experimental reticulate support.

Support for reticulate in current RStudio stable releases (<1.2) is pretty flaky and any hope of using RStudio <1.2 as a Python IDE falls apart as soon as you try to work with imported modules. This is mentioned as an offhand comment in the reticulate docs:

Note that the RStudio v1.2 preview release includes support for using reticulate to execute Python chunks within R Notebooks. See the RStudio IDE Tools for reticulate article for additional details.

Your code doesn't throw an error in RStudio 1.2:

> library(reticulate)
> os <- import("os")
> os$listdir()
 [1] ".Rhistory"         ".Rproj.user"     
查看更多
登录 后发表回答