0

I want to read a python file in R and I am using reticulate package for that.

I have certain packages in python file. Do I have to install them in R env again somehow, for the file to run? And how do I do that? I am getting this error:

  Error in py_run_file_impl(file, local, convert) : 
  ModuleNotFoundError: No module named 'descartes'

How do I fix this?

Mansi
  • 313
  • 1
  • 5
  • 10
  • Just install them directly in python, and it should work – Oliver Jun 15 '20 at 06:54
  • @Oliver It didn't work. I had to use `py_install("package_name")` for all packages. Any way I could create a requirements file and install all packages in R IDE? – Mansi Jun 15 '20 at 07:20

1 Answers1

1

What worked for me was first installing the python customLibrary via the python command line interface.

Second, in my R project folder I specified the python function in a file customLibrary.py which specifies import as first line, such as:

import customLibrary as CL
def custoFunction(path):
   A = CL.test(path)
   return(A)

Third, I call the function from R via standard reticulate::source_python("customLibrary.py") implementation (You may need to check whether your directory-path is correct via R command getwd().)

It may be helpful to start with small steps to narrow down the issue:

  • just write a simple function, such as "addThree" that is essentially y = x + 3 etc.
  • try to execute it in python
  • try to execute if from R

If both works you can try to do the same thing with the custom library.

Simon Stolz
  • 207
  • 2
  • 7