4

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.

  • Could you share the result of `py_config()`? Do you get error when this line executes `os <- import("os")`? Any errors during reticulate installation or library loading? – Yuan Tang Mar 29 '18 at 04:53
  • in addition to `py_config()`, what is the result of `py_available(TRUE)`? – Tonio Liebrand Mar 29 '18 at 12:28
  • I have edited my post by adding outputs which you asked for. I don't get any errors while installation or loading the library, or even when I run the `os <- import("os")` line. But when I start to use any of the `os` module commands it throws the error. What is unexpected for me is that it throws it while I start writing `os$listdir`. – Paweł Kozielski-Romaneczko Mar 29 '18 at 13:41
  • 2
    Maybe I should mention that I am on my work computer, and there may be some issues because of the firewall or because I don't have admin status. Yesterday I installed `reticulate` on my personal computer, where I have the same Python and Anaconda version and it worked like a charm. – Paweł Kozielski-Romaneczko Mar 29 '18 at 13:50
  • Was this issue ever resolved? I'm running into the same problem. Works for personal computer, but not for work computer. – PVic Aug 27 '19 at 15:35

2 Answers2

3

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"     
strangeloop
  • 193
  • 2
  • 12
0

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.

PVic
  • 417
  • 1
  • 4
  • 13