问题
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.
回答1:
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"
回答2:
I was able to get this resolved for my work computer. I'm not sure if it's the reason, but I noticed that my R.exe & python.exe were saved in different driver names. One in C: & the other in X:. So, what I did was uninstall R & python then saved them both into the same driver. This is how I resolved my issue.
来源:https://stackoverflow.com/questions/49533520/modulenotfounderror-no-module-named-rpytools-while-using-reticulate-library