46

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.

nishith
  • 783
  • 1
  • 8
  • 17
  • I also have the same error - creating dedicated virtual environment helped. – Khozzy Jun 23 '17 at 21:48
  • 3
    `pip install --upgrade google-cloud-speech` and `from __future__ import absolute_import` worked for me. Thanks. – Ryan Aug 06 '18 at 16:35

10 Answers10

20

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

My Head Hurts
  • 36,367
  • 15
  • 69
  • 110
George
  • 1,184
  • 6
  • 11
  • 5
    Right answer. You need to tweak the command to install other google-cloud package. For example for me it was `pip install google-cloud-storage` – Astariul Jun 17 '20 at 08:03
13

use this:

pip install google-cloud-bigquery
Paul Roub
  • 35,100
  • 27
  • 72
  • 83
Gunjan Paul
  • 315
  • 2
  • 9
4

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

kgb26
  • 145
  • 12
4

"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.

Bira
  • 2,485
  • 1
  • 20
  • 35
3

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
Luís De Marchi
  • 935
  • 12
  • 23
2

Try this:

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

According to Ref.

hxysayhi
  • 1,431
  • 13
  • 22
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
Dave Challis
  • 2,905
  • 1
  • 29
  • 56
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

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.

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: googleapis-publisher@google.com
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)

Atheel Massalha
  • 332
  • 1
  • 4
  • 14