Python 导入错误:没有名为“google”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36183486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:31:13  来源:igfitidea点击:

ImportError: No module named 'google'

pythonspyder

提问by praveen

This is not a duplicate. My scenario is a bit different and I could not find a solution from similar posts here. I installed Python 3.5. I ran the pip install google command and verified the modules. Google was present. I installed Anaconda 3.5 and tried to run z sample code. But I'm getting the import error. Please find the screen shot attached. What am I missing? Do I have to link my Spyder to Python installation directory in some way? Why is Spyder unable to google module?

这不是重复的。我的情况有点不同,我无法从这里的类似帖子中找到解决方案。我安装了 Python 3.5。我运行了 pip install google 命令并验证了模块。谷歌在场。我安装了 Anaconda 3.5 并尝试运行 z 示例代码。但我收到导入错误。请找到所附的屏幕截图。我错过了什么?我是否必须以某种方式将我的 Spyder 链接到 Python 安装目录?为什么 Spyder 无法 google 模块?

My Python installation directory: C:\Users\XXX\AppData\Local\Programs\Python\Python35 enter image description here

我的Python安装目录:C:\Users\XXX\AppData\Local\Programs\Python\Python35 在此处输入图片说明

enter image description here

在此处输入图片说明

采纳答案by praveen

I figured out the solution:

我想出了解决方案:

  • I had to delete my anaconda and python installations
  • Re-install Anaconda only
  • Open Anaconda prompt and point it to Anaconda/Scripts
  • Run pip install google
  • Run the sample code now from Spyder.
  • 我不得不删除我的 anaconda 和 python 安装
  • 仅重新安装 Anaconda
  • 打开 Anaconda prompt 并将其指向 Anaconda/Scripts
  • pip install google
  • 现在从 Spyder 运行示例代码。

No more errors.

没有更多的错误。

回答by Saber

According to https://developers.google.com/api-client-library/python/apis/oauth2/v1you need to install google-api-python-client package:

根据https://developers.google.com/api-client-library/python/apis/oauth2/v1你需要安装 google-api-python-client 包:

pip install --upgrade google-api-python-client

回答by Darshit Shah

Use this both installation and then go ahead with your python code

使用这两个安装然后继续你的python代码

pip install google-cloud    
pip install google-cloud-vision

回答by Arkil Shaikh

I faced the same issue, I was trying to import translate from google.cloud but kept getting same error.

我遇到了同样的问题,我试图从 google.cloud 导入翻译,但一直遇到同样的错误。

This is what I did

这就是我所做的

  1. pip install protobuf
  2. pip install google-cloud-translate
  1. pip install protobuf
  2. pip install google-cloud-translate

and to install storage service from google google-cloud-storageshould be installed separately

并从谷歌安装存储服务google-cloud-storage应单独安装

Ref - https://cloud.google.com/python/

参考 - https://cloud.google.com/python/

回答by Ratnesh Sharma

I could fix it by installing the following directly.

我可以通过直接安装以下内容来修复它。

pip install google.cloud.bigquery
pip install google.cloud.storage

回答by Chenxi Rao

I solved the problem in this way:

我以这种方式解决了这个问题:

  1. sudo pip install conda
  2. pip install google
  1. 须藤 pip 安装 conda
  2. pip 安装谷歌

and no more error.

没有更多的错误。

回答by smsivaprakaash

I found a similar error when i tried to access the bigquery from google.cloud.

当我尝试从 google.cloud 访问 bigquery 时,我发现了类似的错误。

from google.cloud import bigquery

Error was resolved after i install the google.cloud from conda-forge community.

我从 conda-forge 社区安装 google.cloud 后,错误得到解决。

conda install -c conda-forge google-cloud-bigquery

回答by Ferenc Pal

I had a similar import problem. I noticed that there was no __init__.pyfile in the root of the googlepackage. So, I created an empty __init__.pyand now the import works.

我有一个类似的导入问题。我注意到包__init__.py的根目录中没有文件google。所以,我创建了一个空的__init__.py,现在导入工作。

回答by Mohan. A

  1. Close Anaconda/Spyder
  2. Open command prompt and run the below command
  3. conda update --all
  4. Start the app again and this time it should work.
  1. 关闭 Anaconda/Spyder
  2. 打开命令提示符并运行以下命令
  3. 康达更新 --all
  4. 再次启动应用程序,这次它应该可以工作了。

Note - You need not have to uninstall/reinstall anything.

注意 - 您无需卸载/重新安装任何东西。