我在Mac OS上安装了umap-learn并尝试在r markdown文件中使用它,使用rPython的方式如下所述: http://blog.schochastics.net/post/using-umap-in-r-with-rpython/#fn1 。但是当我运行以下代码时:
我收到了错误信息:
```{r}
umap <- function(x,n_neighbors=10,min_dist=0.1,metric="euclidean"){
x <- as.matrix(x)
colnames(x) <- NULL
rPython::python.exec( c( "def umap(data,n,mdist,metric):",
"\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,metric)
do.call("rbind",res)
}
data(iris)
res <- umap(iris[,1:4])
```
我收到了错误信息:
看起来,Error in python.exec(python.command) : No module named 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])