1

I am trying to access Google Cloud Vision API to perform OCR from Raspberry Pi 3. I have followed the instructions in the given link -

https://cloud.google.com/vision/docs/libraries#client-libraries-install-python

However, when I try to import the library using the following code, I an error as shown below -

import io
import os

# Imports the Google Cloud client library
from google.cloud import vision

I get this error. I have navigated inside the directory - /usr/local/lib/python3.4/dist-packages/google/auth/transport/ and I have found the requests.py file. I have also installed the Python requests module. In spite of that I get the following error.

/usr/local/lib/python3.4/dist-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.9.1) or chardet (2.3.0) doesn't match a supported version!
  RequestsDependencyWarning)
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/google/auth/transport/requests.py", line 23, in <module>
    import requests
  File "/usr/local/lib/python3.4/dist-packages/requests/__init__.py", line 90, in <module>
    from urllib3.exceptions import DependencyWarning
ImportError: cannot import name 'DependencyWarning'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "gc.py", line 7, in <module>
    from google.cloud import vision
  File "/usr/local/lib/python3.4/dist-packages/google/cloud/vision.py", line 20, in <module>
    from google.cloud.vision_v1 import enums
  File "/usr/local/lib/python3.4/dist-packages/google/cloud/vision_v1/__init__.py", line 22, in <module>
    from google.cloud.vision_v1.gapic import image_annotator_client as iac
  File "/usr/local/lib/python3.4/dist-packages/google/cloud/vision_v1/gapic/image_annotator_client.py", line 18, in <module>
    import google.api_core.gapic_v1.client_info
  File "/home/pi/.local/lib/python3.4/site-packages/google/api_core/gapic_v1/__init__.py", line 17, in <module>
    from google.api_core.gapic_v1 import method
  File "/home/pi/.local/lib/python3.4/site-packages/google/api_core/gapic_v1/method.py", line 22, in <module>
    from google.api_core import grpc_helpers
  File "/home/pi/.local/lib/python3.4/site-packages/google/api_core/grpc_helpers.py", line 27, in <module>
    import google.auth.transport.requests
  File "/usr/local/lib/python3.4/dist-packages/google/auth/transport/requests.py", line 31, in <module>
    caught_exc,
  File "<string>", line 3, in raise_from
ImportError: The requests library is not installed, please install the requests package to use the requests transport.

Please help.

EDIT -

I tried sudo pip3 install --upgrade requests and got the following status -

Requirement already up-to-date: requests in /usr/local/lib/python3.4/dist-packages
Cleaning up...
2
  • Could you try the following and tell me what happens after you try to run again your code? sudo pip install --upgrade requests (If you have Python 2.7 and 3.4, probably you have to use pip3) Commented Apr 18, 2018 at 14:14
  • @Mangu Please check the Edit Commented Apr 18, 2018 at 14:26

1 Answer 1

1

After some investigation, I would say this issue is more related to the usage of wrong/not updated dependencies rather than with the Cloud Vision API libraries themselves.

According to the error message you are getting, it looks like the requests library is not found, and also DependencyWarning cannot be imported, however, after running sudo pip3 install --upgrade requests it says that the library is already up-to-date. Therefore, I suspect that either there is an issue with the installation itself.

I would suggest that you do the following steps (use pip3 if necessary):

# Upgrade pip
$ sudo pip install --upgrade pip

# Uninstall then re-install requests
$ sudo pip uninstall requests
$ sudo pip install --upgrade requests

# Upgrade the urllib3 and chardet libraries mentioned in the warning
$ sudo pip install --upgrade urllib3
$ sudo pip install --upgrade chardet

If none of this works, it may be that the issue is with Python 3 itself. Can you test the same using Python 2 and confirm whether it fails with that version too?

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for replying. I have tried the above steps but it did not work. However, I had a fresh installation of Raspbian released on April,2018 and it worked in that. I have tried the same on 2 other new Raspbian installs and it worked on only one of them. I guess the problem is related to OS rather than Python or Google API as such.
I am glad that you got it working in a fresh install. Based on your explanations, it definitely looks like the issue can be related to the OS itself, if it is the case that you have the same configuration and do the same steps as you were doing in the previous (failing) attempts. Also, if you ever find a solution to your own question, feel free to post it and accept it, so that it helps other members of the community too. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.