3

I am starting using reticulate package that allows using Python within R environment and wanted to perform mean-shift clustering with sklearn. So here's my attempt:

> 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.

As you can see, numpy was not found while calling sklearn function while it is imported without a problem with reticulate::import. I have also checked the version of numpy I have in conda prompt and it is 1.15.4. Also py_numpy_available() returns false. My reticulate config are:

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

How can I fix this issue?

jakes
  • 1,964
  • 3
  • 18
  • 50
  • Please don't use the `r` tag for non-r questions. – NelsonGon Jan 07 '19 at 07:02
  • 3
    @NelsonGon, `reticulate` is a package that allows using `python` in `r` so how is it non-r question? I think the whole setup is on `r` side. – jakes Jan 07 '19 at 07:04
  • 1
    If someone simply looks at this question, there's no way to tell it's an R question. One would see python code and assume it's a python question. Perhaps make it more explicit? – NelsonGon Jan 07 '19 at 07:05
  • 1
    Ok, I've just edited to point it out at the beginning. – jakes Jan 07 '19 at 07:08

1 Answers1

1

Take a look at this thread for more information.

I got the same error while trying to call a function from a python script with R objects as arguments. Apparently this happens because Python hasn't been added to your PATH (that is what was adviced during Anaconda installation), which prevents reticulate from finding numpy when initializing python. Adding python to your PATH in R before initializing it with reticulate is what solved the issue for me. So from the aformentioned thread:

if(.Platform$OS.type == "windows") Sys.setenv(PATH= paste("C:/Anaconda3/Library/bin",Sys.getenv()["PATH"],sep=";"))
library(reticulate)