Can not import google.cloud module in python script - python

I am following this article trying to make my Python script read labels related to an image using Google Cloud Vision API. The problem is that I am getting this error when trying to include a reference to vision from google.cloud module.
import io
from google.cloud import vision
from google.cloud.vision import types
The error that I am getting says:
ImportError: No module named 'google.cloud'
This is weird because when I do:
$ pip show google-cloud
I can see it is there and its files are located at:
/usr/local/lib/python2.7/dist-packages/google_cloud-0.34.0.dist-info/*
Except for that, when I do pip freeze in my working folder I can see them both that I need available:
google-cloud==0.34.0
google-cloud-vision==0.33.0
I am now wondering what could be the reason for not being able to see include this module in my Python script.

The google-cloud package is deprecated, you should uninstall it and install google-cloud-vision instead.

This link might provide some assistance:
https://cloud.google.com/python/
Edited
upon looking into it further, I was able to do the following:
pip install google-cloud-vision
and import everything with:
import io
import os
from google.cloud import vision
from google.cloud.vision import types
Maybe try uninstalling the package through pip and reinstalling it with the above?

Related

Cannot import Azure Storage Blob package even though it is installed

I want to write a script to upload files to Azure Blob Storage. I installed the Azure Storage Blob package following this documentation and then tried to run from azure.storage.blob import BlobServiceClient I got the error:
No module named 'azure.storage'; 'azure' is not a package.
When I run pip show azure-storage-blob the package is in the expected place that is included in PATH.
The strange thing is that I can run import azure just fine but when I run pip show azure I get
WARNING: Package(s) not found: azure
This doesnt work either: from azure import BlobServiceClient.
I am using Anaconda / Windows and I tried this with Python 3.6, 3.7 and 3.8 with the same results.
Any help would be greatly appreciated. Thank you.
This issue was solved by Eric Truett's comment, add it as the answer to close the question:
Try launching the anaconda prompt,
then type ipython,
then, in ipython, try from azure.storage.blob import BlobServiceClient.
If you get an ImportError, then try !pip install azure-storage-blob and then try the import again.
I tried from azure.storage.blob import BlobServiceClient and got no
error. So I went to Spyder and just ran the import there. It worked. I
did not change anything else but it is working now.

ImportError: cannot import name 'bigquery_storage_v1beta1' from 'google.cloud' (unknown location)

I'm trying to use bigquery_storage to get data from google cloud big query according to this document. However, after install all the modules (including the installation pip install --upgrade 'google-cloud-bigquery[bqstorage,pandas]'), I kept receiving this error:
Traceback (most recent call last):
File "main.py", line 3, in <module>
from google.cloud import bigquery_storage_v1beta1
ImportError: cannot import name 'bigquery_storage_v1beta1' from 'google.cloud' (unknown location)
My import code:
import os
from google.cloud import storage
from google.cloud import bigquery
from google.cloud import bigquery_storage_v1beta1
And both bigquery and storage are imported. bigquery storage is indeed installed according to pip show google-cloud-bigquery-storage:
Name: google-cloud-bigquery-storage
Version: 2.0.1
Summary: BigQuery Storage API API client library
Home-page: https://github.com/googleapis/python-bigquery-storage
Author: Google LLC
Author-email: googleapis-packages#google.com
License: Apache 2.0
Location: /home/phuong_anh_nguyen/coop/venv/lib/python3.7/site-packages
Requires: libcst, google-api-core, proto-plus
Required-by:
I'm also in my venv and python version is 3.7. Does anybody know why this happens and how to solve it? I've been uninstalling, reinstalling and upgrading packages for a thousand times in different order and none has worked so far. I had this problem before and somehow it got resolved after maniacally installing packaes. I'm looking for a clear answer at last.
I originally wanted to import bigquery_storage_v1beta1 because that's how you download a table on bigquery to pandas dataframe according to GCP's documentation. What I found out was:
As Sergey said, the library is going to be deprecated soon, new code should use v1
You don't need the library to download the data into a pandas dataframe: https://github.com/googleapis/google-cloud-python/issues/10083
Would still be nice to know why this happened tho
Did you try from google.cloud import bigquery_storage instead? Google docs recommend it.
In order to use bigquery_storage_v1beta1 you should pip install google-cloud-bigquery-storage instead. But it is going to be deprecated soon.

ImportError: cannot import name 'types' from 'google.cloud.vision' though I have google cloud vision installed

I have installed google-cloud-vision library following the documentation. It is for some reason unable to import types from google.cloud.vision. It worked fine on my pc, now when I shared with my client, he had a problem with imports though he has the library installed via pip. Here's the line that throws error:
from google.cloud import vision
from google.cloud.vision import types # this line throws error
Any idea how to resolve this issue?
Use from google.cloud.vision_v1 import types instead of from google.cloud.vision import types.I have get this by exploring the init.py file and it works.
Types module has been removed from google.cloud.vision from 2.0.0. You can access all the types from vision.
https://googleapis.dev/python/vision/latest/UPGRADING.html#enums-and-types
Before:
from google.cloud import vision_v1
likelihood = vision_v1.enums.Likelihood.UNKNOWN
request = vision_v1.types.GetProductSetRequest(name="name")
After:
from google.cloud import vision_v1
likelihood = vision_v1.Likelihood.UNKNOWN
request = vision_v1.GetProductSetRequest(name="name")
It's probably because there's some version mismatch (or less likely there's other library(s) with the same name). Have your client use a virtual environment. This should resolve the issue.
P.S. You'll have to provide him with a requirements.txt file (obtained from pip3 freeze) so that he can do a pip3 install -r requirements.txt on his virtual environment to have the exact same packages as yours.

How can I fix import error using google colab?

I'm following this guide, but I have a lot of issues already in the INITIALIZATION.
I use Google Colab and I have done the pip install with pip install git+https://github.com/microsoft/ComputerVision.git#master#egg=utils_cv
When running the first error is ImportError: cannot import name 'Video'
with the line from IPython.display import Video
I have no idea to fix it, some one can help?

Python Linux Google drive API client install modules not found

I'm trying to start working with google drive API from python on my local Linux machine. I want to be able to move files back and forth to Google drive from my local machine. I just started learning Python yesterday and I'm having problems with the Google quickstart instructions. when I try to run the quickstart code at https://developers.google.com/drive/v3/web/quickstart/python with python3 I get this error:
ImportError: No module named 'apiclient.discovery'
which results from these import statements at the top of the file.
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
As per the instructions I installed what I thought i needed with the command
pip install --upgrade google-api-python-client
But I'm getting this error. I notice if i comment out the line
from apiclient.discovery import build
then the rest of the import statements are ok, and the script starts executing and browser pops up asking for authentication, but then obviously when it reachs the 'build' function call in the script it breaks. What am I doing wrong?
I've tried installing the lib folder containing the modules to the local directory where my script is executing, but I think that's only important if you're using google app engine which I am .... not? I don't think I am right? When i did that i tried changing the import statement to
from lib.googleapiclient.discovery import build
I get the same error, but I've actually opened up that file in lib/googleapiclient/discovery.py in my local directory and in the code is
...
def build(serviceName,
version,
http=None,
discoveryServiceUrl=DISCOVERY_URI,
developerKey=None,
model=None,
requestBuilder=HttpRequest,
credentials=None,
cache_discovery=True,
cache=None):
...
So why in the world wouldn't this import statement work? I've also tried changing the statements from
from apiclient.discovery import build
to
from googleapiclient.discovery import build
and I get the same error, No module named 'googleapiclient'
I've installed 3rd party modules yesterday with pip and I never had any problems. What's going on? Thanks for your help.
Check your python and pip version, and try pip freeze to check the installed package.
python --version
pip --version
pip freeze
Please check your python version, where your pip is from (/usr/lib/python2.7 or /usr/lib/python3.6 or the other virtualenv) and whethergoogle-api-python-client is in the output of pip freeze.
Try to reinstall google-api-python-client.
sudo pip install --force-reinstall google-api-python-client
apiclient is the old name, so it is better to use googleapiclient for import.
from googleapiclient.discovery import module

Categories