我正在尝试在Mac(Mojave 10.14.5)上运行Gmail API Python Quickstart
我已经这样安装了Google客户端库:
sudo -H pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
这是输出:
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Requirement already up-to-date: google-api-python-client in /private/var/root/Library/Python/2.7/lib/python/site-packages (1.7.9)
Requirement already up-to-date: google-auth-httplib2 in /private/var/root/Library/Python/2.7/lib/python/site-packages (0.0.3)
Requirement already up-to-date: google-auth-oauthlib in /private/var/root/Library/Python/2.7/lib/python/site-packages (0.3.0)
Requirement already satisfied, skipping upgrade: httplib2<1dev,>=0.9.2 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from google-api-python-client) (0.12.3)
Requirement already satisfied, skipping upgrade: uritemplate<4dev,>=3.0.0 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from google-api-python-client) (3.0.0)
Requirement already satisfied, skipping upgrade: six<2dev,>=1.6.1 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from google-api-python-client) (1.12.0)
Requirement already satisfied, skipping upgrade: google-auth>=1.4.1 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from google-api-python-client) (1.6.3)
Requirement already satisfied, skipping upgrade: requests-oauthlib>=0.7.0 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from google-auth-oauthlib) (1.2.0)
Requirement already satisfied, skipping upgrade: cachetools>=2.0.0 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from google-auth>=1.4.1->google-api-python-client) (3.1.1)
Requirement already satisfied, skipping upgrade: rsa>=3.1.4 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from google-auth>=1.4.1->google-api-python-client) (4.0)
Requirement already satisfied, skipping upgrade: pyasn1-modules>=0.2.1 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from google-auth>=1.4.1->google-api-python-client) (0.2.5)
Requirement already satisfied, skipping upgrade: requests>=2.0.0 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib) (2.22.0)
Requirement already satisfied, skipping upgrade: oauthlib>=3.0.0 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib) (3.0.1)
Requirement already satisfied, skipping upgrade: pyasn1>=0.1.3 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from rsa>=3.1.4->google-auth>=1.4.1->google-api-python-client) (0.4.5)
Requirement already satisfied, skipping upgrade: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib) (1.25.3)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib) (2019.3.9)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib) (3.0.4)
Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /private/var/root/Library/Python/2.7/lib/python/site-packages (from requests>=2.0.0->requests-oauthlib>=0.7.0->google-auth-oauthlib) (2.8)
但是当我尝试运行快速入门时:
>python quickstart.py
Traceback (most recent call last):
File "quickstart.py", line 4, in <module>
from googleapiclient.discovery import build
ImportError: No module named googleapiclient.discovery
现在,如果我注释掉第4行,我会得到:
>python quickstart.py
Traceback (most recent call last):
File "quickstart.py", line 5, in <module>
from google_auth_oauthlib.flow import InstalledAppFlow
ImportError: No module named google_auth_oauthlib.flow
如果我注释掉第5行,我会得到:
>python quickstart.py
Traceback (most recent call last):
File "quickstart.py", line 6, in <module>
from google.auth.transport.requests import Request
ImportError: No module named google.auth.transport.request
我还尝试重新启动终端-并重新启动计算机。
为什么找不到任何Google客户端库模块?
答案 0 :(得分:0)
我不确定为什么-但也许不支持Python 2.x吗?
一旦我使用Python 3.x,一切都将正常工作:
安装:
sudo -H pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
运行脚本:
python3 quickstart.py
答案 1 :(得分:-1)
pip install google-auth-oauthlib