[英]can't import package with rPython
I installed umap-learn
on mac OS
and tried to use it in r markdown
file using rPython
the way it is explained here: 我在
mac OS
上安装了umap-learn
,并尝试使用rPython
在r markdown
文件中使用它,如下所述:
http://blog.schochastics.net/post/using-umap-in-r-with-rpython/#fn1 http://blog.schochastics.net/post/using-umap-in-r-with-rpython/#fn1
But when I run following code: 但是当我运行以下代码时:
```{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])
```
I get the error: 我收到错误:
Error in python.exec(python.command) : No module named umap
python.exec中的错误(python.command):没有名为umap的模块
So, apparently Rstudio
does not see the umap
. 所以,显然
Rstudio
没有看到umap
。 I checked that the package is installed by conda list
: 我检查了包是由
conda list
安装的:
umap-learn 0.2.3 py36_0 conda-forge
How could I fix that? 我怎么能解决这个问题?
Update
更新
The version of python was wrong, so I added .Rprofile
and made it point to the right version, however, the error persisted. python的版本是错误的,所以我添加了
.Rprofile
并使其指向正确的版本,但是,错误仍然存在。
system("python --version")
Python 3.6.5 :: Anaconda, Inc.
Update
更新
More detailed error (stack trace): 更详细的错误(堆栈跟踪):
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])
You need to make sure that umap
is available to the same Python used in R, which is not going to be your Anaconda installation by default. 您需要确保
umap
可用于R中使用的相同Python,默认情况下不会是您的Anaconda安装。
You can check your Python with system("python --version")
and if needed go on the cmd
line and do pip install umap
or pip3 install umap
etc (to use the currently available Python; alternately you can switch the Python path to your Anaconda Python). 你可以用
system("python --version")
检查你的Python system("python --version")
,如果需要,可以在cmd
行上进行pip install umap
或pip3 install umap
等(使用当前可用的Python;或者你可以将Python路径切换到你的Anaconda Python)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.