3

我开始使用reticulate允许在 R 环境中使用 Python 的包,并希望使用sklearn. 所以这是我的尝试:

> library(reticulate)
> np <- import('numpy')
> sklearn <- import('sklearn')
> sklearn.MeanShift <- sklearn$cluster$MeanShift
> x <- matrix(rnorm(20), 10, 2)
> sklearn.MeanShift(x)
Error in py_call_impl(callable, dots$args, dots$keywords) : 
  Evaluation error: Required version of NumPy not available: installation of Numpy >= 1.6 not found.

如您所见,在导入函数时调用函数时numpy找不到. 我还检查了我在 conda 提示符下的版本,它是 1.15.4。也返回假。我的配置是:sklearnreticulate::importnumpypy_numpy_available()reticulate

python:         C:\Users\jakes\ANACON~1\python.exe
libpython:      C:/Users/jakes/ANACON~1/python37.dll
pythonhome:     C:\Users\jakes\ANACON~1
version:        3.7.1 (default, Oct 28 2018, 08:39:03) [MSC v.1912 64 bit (AMD64)]
Architecture:   64bit
numpy:           [NOT FOUND]
scikit-learn:   [NOT FOUND]

python versions found: 
 C:\Users\jakes\ANACON~1\python.exe
 C:\Users\jakes\Anaconda3\python.exe

我该如何解决这个问题?

4

1 回答 1

1

查看此线程以获取更多信息。

尝试从以 R 对象作为参数的 python 脚本调用函数时,我遇到了同样的错误。显然,发生这种情况是因为 Python 尚未添加到您的 PATH(这是在 Anaconda 安装期间建议的),这会阻止 reticulate 在初始化 python 时找到 numpy。在使用 reticulate 初始化它之前将 python 添加到 R 中的 PATH 是解决我的问题的方法。所以从上述线程:

if(.Platform$OS.type == "windows") Sys.setenv(PATH= paste("C:/Anaconda3/Library/bin",Sys.getenv()["PATH"],sep=";"))
library(reticulate)
于 2019-01-08T10:42:22.413 回答