Python R 中的环境:在 R 中安装 python 包
Python env in R: Installing python packages in R
我想在 R 中读取一个 python 文件,为此我正在使用网状包。
我在 python 文件中有某些包。我是否必须以某种方式再次将它们安装在 R env 中,以便将文件添加到 运行?我该怎么做?
我收到此错误:
Error in py_run_file_impl(file, local, convert) :
ModuleNotFoundError: No module named 'descartes'
我该如何解决这个问题?
对我有用的是首先安装 python customLibrary via the python command line interface。
其次,在我的 R 项目文件夹中,我在文件 customLibrary.py 中指定了 python 函数,该函数将导入指定为第一行 ,例如:
import customLibrary as CL
def custoFunction(path):
A = CL.test(path)
return(A)
第三,我通过标准 reticulate::source_python("customLibrary.py")
实现从 R 调用该函数(您可能需要通过 R 命令 getwd()
检查您的目录路径是否正确。)
从小步骤开始可能有助于缩小问题范围:
- 只写一个简单的函数,比如“addThree”本质上就是
y = x + 3
等
- 尝试在python
中执行
- 如果从R
尝试执行
如果两者都有效,您可以尝试对自定义库执行相同的操作。
我想在 R 中读取一个 python 文件,为此我正在使用网状包。
我在 python 文件中有某些包。我是否必须以某种方式再次将它们安装在 R env 中,以便将文件添加到 运行?我该怎么做? 我收到此错误:
Error in py_run_file_impl(file, local, convert) :
ModuleNotFoundError: No module named 'descartes'
我该如何解决这个问题?
对我有用的是首先安装 python customLibrary via the python command line interface。
其次,在我的 R 项目文件夹中,我在文件 customLibrary.py 中指定了 python 函数,该函数将导入指定为第一行 ,例如:
import customLibrary as CL
def custoFunction(path):
A = CL.test(path)
return(A)
第三,我通过标准 reticulate::source_python("customLibrary.py")
实现从 R 调用该函数(您可能需要通过 R 命令 getwd()
检查您的目录路径是否正确。)
从小步骤开始可能有助于缩小问题范围:
- 只写一个简单的函数,比如“addThree”本质上就是
y = x + 3
等 - 尝试在python 中执行
- 如果从R 尝试执行
如果两者都有效,您可以尝试对自定义库执行相同的操作。