ImportError: No module named google.cloud
Asked Answered
U

16

76

I am unable to import google.cloud.speech

from google.cloud import speech

I have installed it using :

pip install --upgrade google-cloud-speech -t dir-name

It is giving me below error while importing it from dir-name

ImportError: No module named google.cloud

google package with all the sub package is present over there but without __init__.py in every sub packages as well.

How can I import this packages without adding __init__.py in package folder?

PS : I have also tried from __future__ import absolute_import, but its not working.

Urien answered 6/6, 2017 at 18:39 Comment(3)
I also have the same error - creating dedicated virtual environment helped.Dichasium
pip install --upgrade google-cloud-speech and from __future__ import absolute_import worked for me. Thanks.Quittor
for me it was absolute impor - pip install google-cloud-dialogflowLaniferous
S
30

The instructions on the "Cloud Speech API Client Libraries" documentation page are now valid and the install is successful, as desired.

I installed the library for Python on my Debian machine using the command:

pip install --upgrade google-cloud-speech

Swirsky answered 5/10, 2017 at 15:44 Comment(2)
Right answer. You need to tweak the command to install other google-cloud package. For example for me it was pip install google-cloud-storageIniquitous
Not really @Iniquitous (March 2023)Morman
G
27

use this:

pip install google-cloud-bigquery
Grandpa answered 23/8, 2019 at 18:42 Comment(1)
and if running in a notebook, restart kernel and reimportHenrion
G
7

I used sudo python -m pip install google-cloud instead and it worked.

Glaser answered 17/7, 2017 at 11:46 Comment(1)
The specific libraries seem to need to be specified now. "google-cloud-*"Amethist
M
6

"No module named google.cloud" you need a python environment for google cloud.

pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install <google-cloud>

<google-cloud> replace this with required library. e.g: google-cloud-vision or google-cloud-storage, etc

<your-env> is a folder name, which is going to be store all python environment related things inside your project.

Meredithmeredithe answered 16/1, 2019 at 9:30 Comment(1)
It is not mandatory to use a python environment for Google Cloud.Neva
L
4

After many hours with the same problem, I discovered the solution: Import the library "get_messages" before importing something from "google.cloud". This worked in Python 3:

from google.api_core.protobuf_helpers import get_messages
from google.cloud import speech
Lebkuchen answered 20/2, 2019 at 4:58 Comment(1)
this solved google.cloud, but now I ger "No module named 'google.api_core'"Morman
H
4

The google.cloud is deprecated post June 18, you should install specific extension of your package

pip install google-cloud-{x}

Use

Source: github discussion

Heinrich answered 19/8, 2021 at 11:2 Comment(1)
@Urien please mark a solution as complete if it solves your requestHeinrich
A
2

Try this:

$ git clone https://github.com/GoogleCloudPlatform/google-cloud-python
$ cd google-cloud-python/speech
$ python setup.py install

According to Ref.

Apothecium answered 17/7, 2017 at 12:1 Comment(0)
K
1

After you install google-api-python-client, you have to specify what exact google cloud product you want to install.

So for pubsub it is:

$pip3 install --upgrade google-cloud-pubsub
Kumiss answered 15/7, 2020 at 15:22 Comment(0)
K
1

I struggled with the same problem recently. 2 things solved it for me:

Installing the following packages

google-api-core==1.22.1 
google-auth==1.20.1
google-cloud-texttospeech==2.2.0
googleapis-common-protos==1.52.0
graphviz==0.13.2
greenlet==0.4.16
grpcio==1.31.0
gTTS==2.1.1
gTTS-token==1.1.3

If this doesn't work, try switching to Python 3.7

Kutzer answered 18/8, 2020 at 19:16 Comment(1)
I resolved this issue by using python3 on the command line (3.7.3)Moorhead
P
0

I ran into the same problem just recently. My error was caused because I hadn't enabled the Cloud Speech-to-Text API. I was able to do that in cloud console and the error was resolved.

Plainlaid answered 5/8, 2019 at 22:22 Comment(0)
S
0

type this command:

 pip show google-cloud

you should ee an output like this:

Name: google-cloud
Version: 0.34.0
Summary: API Client library for Google Cloud
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google Cloud Platform
Author-email: [email protected]
License: Apache 2.0
Location: c:\users\<user>\appdata\roaming\python\python37\site-packages
Requires:
Required-by:

then take the full location path and add it to PATH (env vars)

Secretive answered 10/8, 2019 at 11:18 Comment(0)
M
0

Run

pip install -r requirements.txt

with requirements .txt content being

google-cloud-datastore==1.15.0
Mekka answered 31/7, 2021 at 5:53 Comment(0)
M
0

None of the installs mentioned here helped me. Then I did the following and it worked:

pip install google-cloud-logging

Reference: https://pypi.org/project/google-cloud-logging/

Madwort answered 22/12, 2021 at 18:20 Comment(0)
M
0

This problem disappeared for me when I used a virtual env. My fix looks like this:

-#!/usr/bin/python3
+#!/usr/bin/env python3

FYI I'm using Python 3.8.3 on a MacBook. I didn't see this error with the same code on Ubuntu.

Mariner answered 9/5, 2023 at 17:36 Comment(0)
D
0

Based on Python version you have try:

python3 -m pip install google-cloud-speech

or

python -m pip install google-cloud-speech
Down answered 27/6, 2023 at 10:9 Comment(0)
B
0

For future seekers, in my case i was using a folder named google. So this was conflicting with the lib. For this case, you just need to change the folder's name (i.e.: googlelib)

#from
from google import blabla # this "google" is from your folder

#to
from googlelib import blabla
Butene answered 2/2, 2024 at 20:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.