Search code examples
protocol-buffersgoogle-colaboratoryocr

ContextualVersionConflict error message when using "from google.cloud import vision" on google colab


When I try to run !pip install google-cloud-vision and from google.cloud import visionon google colab

I get the following error:

ContextualVersionConflict (protobuf 3.17.3 (/usr/local/lib/python3.7/dist-packages), Requirement.parse('protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<5.0.0dev,>=3.19.5'), {'google-cloud-vision'})

I try several ways, it is not working

  1. use !ls to check the protobuf in the colab path, it shows "protobuf-4.21.9.dist-info"
  2. try to !pip install protobuf ==4.21.1
  3. !gitclone the whole package of protobuf from github under the colab path of /content

I wonder if i am putting into a wrong route, or is there any thing else i can try to solve this problem.


Solution

  • Hmmm.... I'm not familiar with Google Collab but it appears the default protobuf version is out of date:

    !pip freeze | grep protobuf
    

    Yields:

    protobuf==3.17.3
    

    And:

    !pip install protobuf==4.21.9
    !pip install google-cloud-vision
    !pip freeze | grep protobuf
    

    Yields:

    protobuf==4.21.9
    

    Then:

    from google.cloud import vision
    
    vision
    

    Seems to be ok:

    <module 'google.cloud.vision' from '/usr/local/lib/python3.7/dist-packages/google/cloud/vision/__init__.py'>