ModuleNotFoundError: No module named 'googleapiclient'

ModuleNotFoundError: No module named 'googleapiclient'

当我 运行 我的 venv 中的代码时,我得到 ModuleNotFoundError: No module named 'googleapiclient。但是,当我不在全局范围内激活我的 venv 或 运行 时,代码可以正常工作。尽管,在我的 venv 我有:

google-api-core==1.22.0
google-api-python-client==1.10.0
google-auth==1.19.2
google-auth-httplib2==0.0.4
google-auth-oauthlib==0.4.1
googleapis-common-protos==1.52.0

有人可以解释一下我的 venv 中缺少什么包裹吗?

代码:

from __future__ import print_function
import datetime
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from datetime import datetime, timedelta
import datetime


SCOPES = ['https://www.googleapis.com/auth/calendar']


def main():
    creds = None
    if os.path.exists('token.pickle'):
        with open('token.pickle', 'rb') as token:
            creds = pickle.load(token)
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())

    global service
    service = build('calendar', 'v3', credentials=creds)

if __name__ == '__main__':
    main()

event = {
  'summary': 'Test',
  'location': 'At home',
  'description': 'A chance to hear more about Google\'s developer products.',
  'start': {
    'dateTime': '2020-07-08T12:12:10',
    'timeZone': 'America/Los_Angeles',
  },
  'end': {
    'dateTime': '2020-08-08T12:32:47',
    'timeZone': 'America/Los_Angeles',
  }
}
event = service.events().insert(calendarId='primary', body=event).execute()

1.Install 与 virtualenv

virtualenv temp
source temp/bin/activate
pip install --upgrade google-api-python-client
  1. 忽略六

    sudo pip install --upgrade google-api-python-client --ignore-installed six