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?
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:
y = x + 3
etc.If both works you can try to do the same thing with the custom library.