windows 环境下python和R的交互

Rstudio调用Python模块:
0.查看python路径
sessionInfo()

指定python路径

library(reticulate) #R使用python的工具
path_to_python <- "D:/python"
use_python(path_to_python)
reticulate::use_python(path_to_python)

anndata是python模块,初次运行报错

library(anndata)
ad <- read_h5ad("NB.test.h5ad")
Error in py_module_import(module, convert = convert) :
ModuleNotFoundError: No module named 'anndata'
Run reticulate::py_last_error() for details.

进入R 包中专门放python module的地方reticulate下发现没有anndata

D:\R\R-4.3.1\library\reticulate\python\rpytools

进入win cmd模式用pip安装anndata

pip anndata

python module存放位置,找到anndata,py

D:\python\Lib\site-packages\anndata_core

把anndata.py复制到R reticulate 包下

D:\R\R-4.3.1\library\reticulate\python\rpytools

在R载入module

reticulate::import('anndata')
library(anndata)
ad <- read_h5ad("NB.test.h5ad")

posted on 2024-05-07 21:29  魔法老头  阅读(164)  评论(0)    收藏  举报

导航