Unable to import google.cloud.vision via the reticulate package in R

372 views Asked by At

I am using the reticulate package to import python modules into RStudio.I was able to import packages like cv2,pandas,sklearn but was unable to import the google.cloud.vision package.I have installed this package via pip and am using Anaconda 4.4.0 Python 2.7 version on ubuntu-trusty-14.04-amd64-server on AWS.Pic of the error in R-Studio Server The Installation of the vision and the language libraries was done via

pip install --upgrade google-cloud-vision
pip install --upgrade google-cloud-language

I am also able to import these modules in the python interactive sessions without any error

>>>import google.cloud.vision
>>>import google.cloud.language

Can somebody please advise me on what I am doing wrong...

Edit 1 :I have tried using the approach that Yuan Tang had suggested.I have installed the requests and httplib2 package in the conda environment.I have also used the use_python command to point Rstudio to the correct python environment.

use_python("/home/avadhut/miniconda2/bin/python")

The cv2 package is installed in the conda environment and it is imported successfully which means RStudio is using the correct Python environment

Even after doing all this I am getting the following trace-back in the R studio console.

Error in py_module_import(module, convert = convert) : 
  ImportError: The requests library is not installed, please install the requests package to use the requests transport.

Detailed traceback: 
File "/home/avadhut/miniconda2/lib/python2.7/site-packages/google/cloud/vision/__init__.py", line 36, in <module>
    from google.cloud.vision.client import Client
File "/home/avadhut/miniconda2/lib/python2.7/site-packages/google/cloud/vision/client.py", line 20, in <module>
    from google.cloud.client import ClientWithProject
File "/home/avadhut/miniconda2/lib/python2.7/site-packages/google/cloud/client.py", line 25, in <module>
    import google.auth.transport.requests
File "/home/avadhut/miniconda2/lib/python2.7/site-packages/google/auth/transport/requests.py", line 30, in <module>
    caught_exc,
File "/home/avadhut/miniconda2/lib/python2.7/site-packages/six.py", line 737, in raise_from
    raise value

Here is the pic of my RStudio IDE with the error displayed. !Reticulate Package Import Error

1

There are 1 answers

0
Yuan Tang On

This is because the Python binary you are using inside RStudio via reticulate does not have those packages (e.g. requests, httplib2, etc) installed.

You can find out what Python reticulate is using via py_config(). You can also find the Python binary you are using on the terminal via which python.

Let's suppose the Python binary you are using on the terminal (the successful imports) is: "/Users/user1/anaconda3/bin/python". Then you use that particular Python binary for reticulate via the following:

use_python("/Users/user1/anaconda3/bin/python")

Then your imports should work as expected.