63

我无法导入 google.cloud.speech

from google.cloud import speech

我已经安装了它:

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

从 dir-name 导入时出现以下错误

ImportError: No module named google.cloud

带有所有子包的谷歌包都在那里,但每个子包中也没有__init__ .py 。

如何在不添加__init__ .py 包文件夹的情况下导入这些包?

PS:我也尝试过 from __future__ import absolute_import,但它不起作用。

4

13 回答 13

29

“Cloud Speech API Client Libraries”文档页面上的说明现在有效并且安装成功,如您所愿。

我使用以下命令在我的 Debian 机器上安装了 Python 库:

pip install --upgrade google-cloud-speech

于 2017-10-05T15:44:24.220 回答
21

用这个:

pip install google-cloud-bigquery
于 2019-08-23T18:42:18.273 回答
6

sudo python -m pip install google-cloud改用它,它起作用了。

于 2017-07-17T11:46:06.520 回答
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.

于 2019-01-16T09:30:28.493 回答
3

在遇到同样的问题几个小时后,我发现了解决方案:在从“google.cloud”导入内容之前导入库“get_messages”。这在 Python 3 中有效:

from google.api_core.protobuf_helpers import get_messages
from google.cloud import speech
于 2019-02-20T04:58:00.800 回答
2

尝试这个:

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

根据参考文献

于 2017-07-17T12:01:05.280 回答
2

6 月 18 日后不推荐使用 google.cloud,您应该安装包的特定扩展

pip install google-cloud-{x}

利用

来源:github讨论

于 2021-08-19T11:02:22.713 回答
1

我最近在同样的问题上苦苦挣扎。两件事为我解决了它:

安装以下软件包

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

如果这不起作用,请尝试切换到 Python 3.7

于 2020-08-18T19:16:23.740 回答
1

安装后google-api-python-client,您必须指定要安装的确切谷歌云产品。

所以对于 pubsub 它是:

$pip3 install --upgrade google-cloud-pubsub
于 2020-07-15T15:22:37.893 回答
0

键入此命令:

 pip show google-cloud

你应该看到这样的输出:

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:

然后获取完整的位置路径并将其添加到 PATH (env vars)

于 2019-08-10T11:18:11.047 回答
0

我最近遇到了同样的问题。我的错误是因为我没有启用 Cloud Speech-to-Text API。我能够在云控制台中执行此操作,并且错误已解决。

于 2019-08-05T22:22:03.190 回答
0

这里提到的安装都没有帮助我。然后我做了以下事情,它奏效了:

pip install google-cloud-logging

参考:https ://pypi.org/project/google-cloud-logging/

于 2021-12-22T18:20:09.447 回答
0

pip install -r requirements.txt

要求 .txt 内容为

google-cloud-datastore==1.15.0
于 2021-07-31T05:53:12.340 回答