Краткое руководство по API Gmail: не удается установить клиентскую библиотеку Google Python - PullRequest
1 голос
/ 27 мая 2019

Я пытаюсь запустить Gmail API Python Quickstart на моем Mac (Mojave 10.14.5)

Я установил клиентскую библиотеку 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?

1 Ответ

0 голосов
/ 27 мая 2019

Я не уверен, почему - но, возможно, Python 2.x не поддерживается?

Как только я перешел на Python 3.x, все заработало:

Установка:

sudo -H pip3 install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

Запустить скрипт:

python3 quickstart.py
...