[英]Python env in R: Installing python packages in R
I want to read a python file in R and I am using reticulate package for that.我想在 R 中读取 python 文件,为此我正在使用网状 package。
I have certain packages in python file.我在 python 文件中有某些包。 Do I have to install them in R env again somehow, for the file to run?
我是否必须以某种方式再次将它们安装在 R 环境中,才能运行文件? 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 .对我有用的是首先通过 python 命令行界面安装python customLibrary。
Second, in my R project folder I specified the python function in a file customLibrary.py which specifies import as first line , such as:其次,在我的 R 项目文件夹中,我在 customLibrary.py 文件中指定了 python function,该文件将导入指定为第一行,例如:
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()
.)第三,我通过标准
reticulate::source_python("customLibrary.py")
实现从 R 调用 function (您可能需要通过 ZE1E1D3D40573123E6ZEE04 8 dCAF188 检查您的目录路径是否正确getwd()
。
It may be helpful to start with small steps to narrow down the issue:从小步骤开始缩小问题范围可能会有所帮助:
y = x + 3
etc.y = x + 3
等。If both works you can try to do the same thing with the custom library.如果两者都有效,您可以尝试对自定义库做同样的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.