Python 如何在 Google App Engine 上防止“ImportError: No module named oauth2client.client”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44011776/
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 23:37:58  来源:igfitidea点击:

How to prevent "ImportError: No module named oauth2client.client" on Google App Engine?

pythongoogle-app-engineoauth-2.0

提问by Praxiteles

We are receiving an error:

我们收到一个错误:

ImportError: No module named OAuth2Client

导入错误:没有名为 OAuth2Client 的模块

We have noticed scores of questions around this topic, many unanswered and at least one answer that describes the solution of copying over files from the Google App Engine SDK.

我们注意到围绕该主题存在大量问题,许多问题没有答案,至少有一个答案描述了从 Google App Engine SDK 复制文件的解决方案。

This approach, however, seems tedious because all the dependencies are unclear. If we copy over oauth2clientthen run, the next error is another module that is missing. Fix that, then another module is missing, etc., etc.

但是,这种方法似乎很乏味,因为所有依赖项都不清楚。如果我们复制oauth2client然后运行,下一个错误是缺少另一个模块。修复它,然后另一个模块丢失,等等,等等。

What is ironic is that we can see all the files and modules needed, listed from Google App Engine SDK right in PyCharm but they seem inaccessible to the script.

具有讽刺意味的是,我们可以在 PyCharm 中看到从 Google App Engine SDK 中列出的所有所需文件和模块,但脚本似乎无法访问它们。

Is there no better way to pull in all the files that oauth2clientneeds for Python to work on App Engine?

没有更好的方法来提取oauth2clientPython 在 App Engine 上运行所需的所有文件吗?

采纳答案by Praxiteles

The answer is to "vendor" in the file(s).

答案是文件中的“供应商”。

We found a quick way to solve this based on this documentation https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoringand this SO answer.

我们找到了一种基于此文档https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring和此SO 答案的快速方法来解决此问题

  1. Create a new folder called "lib" in the same folder as your app.yaml file. (You can name it something else. Just use that name below.)

  2. Create an empty file called appengine_config.pyin the same folder as your app.yaml file

  3. Add two lines to that appengine_config.py file:

    from google.appengine.ext import vendor vendor.add('lib')

  4. From terminal, navigate to the directory which contains that file and execute the following command:

    sudo pip install -t lib google-api-python-client

  1. 在 app.yaml 文件所在的文件夹中创建一个名为“ lib”的新文件夹。(您可以将其命名为其他名称。只需在下面使用该名称即可。)

  2. 在 app.yaml 文件所在的文件夹中创建一个名为appengine_config.py的空文件

  3. 向该 appengine_config.py 文件添加两行:

    from google.appengine.ext import vendor vendor.add('lib')

  4. 从终端导航到包含该文件的目录并执行以下命令:

    sudo pip install -t lib google-api-python-client

The import error will disappear and you will have all the sub-dependent modules as well.

导入错误将消失,您还将拥有所有子依赖模块。

回答by Sadegh-khan

I have this problem and solved by installing oauth2clientwith pip3:

我有这个问题,并通过安装解决oauth2clientpip3

pip3 install --upgrade oauth2client 

回答by Sumithran

As per the google-api-pythondocumentation, try this

根据google-api-python文档,试试这个

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

回答by Rahul Bhat

Run this

运行这个

sudo python -m pip install oauth2client

sudo python -m pip install oauth2client

回答by Luis Fernando

Install WHL file

安装WHL 文件

pip install oauth2client-4.1.3-py2.py3-none-any.whl