我在mac OS
上安装了umap-learn
,并尝试使用rPython
在r markdown
文件中使用它,方法如下:
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
没有看到{conda list
安装:
我怎么能修好呢?在
Update
python的版本是错误的,所以我添加了.Rprofile
并使其指向正确的版本,但是错误仍然存在。在
system("python --version")
Python 3.6.5 :: Anaconda, Inc.
Update
更详细的错误(堆栈跟踪):
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])
您需要确保
umap
可用于R中使用的同一个Python,默认情况下这不是Anaconda的安装。在您可以使用}等操作(使用当前可用的Python;或者,switch您的PythonPython的Python路径)。在
system("python version")
来检查您的Python,如果需要,可以在cmd
行执行pip install umap
或{相关问题 更多 >
编程相关推荐