当我在venv中运行代码时,我得到ModuleNotFoundError: No module named 'googleapiclient
。但是,当我不激活我的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()
答案 0 :(得分:0)
1。使用virtualenv安装
virtualenv temp
source temp/bin/activate
pip install --upgrade google-api-python-client
忽略六个
s udo pip install --upgrade google-api-python-client --ignore-installed six