我在mac OS上安装了mac OS,并试图使用rPython在r markdown文件中使用它,如下所示:
http://blog.schochastics.net/post/using-umap-in-r-with-rpython/#fn1
但是当我运行以下代码时:
```{r}-函数(x,n_neighbors=10,min_dist=0.1,metric=“欧几里得”){
X <- as.matrix(x)
colnames(x) <- NULL
rPython::python.exec( c( "def umap(数据,n,mdist,度量)):“,
"\timport umap" , "\timport numpy", "\tembedding = umap.UMAP(n_neighbors=n,min_dist=mdist,metric=metric).fit_transform(data)", "\tres = embedding.tolist()", "\treturn res"))res <- rPython::python.call( "umap",x,n_neighbors,min_dist,度量)
do.call("rbind",res)
}
数据(虹膜)
res <- umap(虹膜,1:4)
我知道错误:
python.exec(python.command)中的错误:没有名为umap的模块
因此,显然Rstudio没有看到umap。我检查了包是否由conda list安装。
umap-learn 0.2.3 py36_0 conda-forge我怎么才能解决这个问题?
更新
python的版本是错误的,所以我添加了.Rprofile并使它指向正确的版本,但是错误仍然存在。
system("python --version")
Python 3.6.5 :: Anaconda, Inc.更新
更详细的错误(堆栈跟踪):
Error in python.exec(python.command) : No module named umap
4.stop(ret$error.desc)
3.python.exec(python.command)
2.rPython::python.call("umap", x, n_neighbors, min_dist, metric)
1.umap(iris[, 1:4])发布于 2018-05-03 18:23:39
您需要确保umap对R中使用的相同的Python可用,默认情况下,这将不是您的Anaconda安装。
您可以使用system("python --version")检查您的Python,如果需要,可以在cmd行上执行pip install umap或pip3 install umap等操作(使用当前可用的Python;或者可以将Python路径switch到Anaconda )。
https://stackoverflow.com/questions/50161533
复制相似问题