gpt4 book ai didi

python - 从谷歌导入Create_Service ModuleNotFoundError : No module named 'Google'

转载 作者:行者123 更新时间:2023-12-01 23:14:33 29 4
gpt4 key购买 nike

我正在尝试在 python 中使用 Gmail api 发送电子邮件,但尽管使用“pip install --upgrade google-api-python-client”或“pip install google”,但仍无法导入 Google 模块。

但是 pip freeze 显示:

asgiref==3.3.4
beautifulsoup4==4.10.0
cachetools==4.2.2
certifi==2021.5.30
cffi==1.14.6
charset-normalizer==2.0.6
dj-database-url==0.5.0
Django==3.2.3
django-ckeditor==6.1.0
django-ckeditor-5==0.0.14
django-heroku==0.3.1
django-js-asset==1.2.2
django-phone-field==1.8.1
django-tawkto==0.3
**google==3.0.0**
google-api-core==2.0.1
google-api-python-client==2.21.0
google-auth==2.1.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.4.6
google-cloud==0.34.0
google-cloud-bigquery==2.26.0
google-cloud-core==2.0.0
google-cloud-storage==1.42.2
google-cloud-vision==2.4.2
google-crc32c==1.1.2
google-resumable-media==2.0.2
googleapis-common-protos==1.53.0
grpcio==1.40.0
gunicorn==20.1.0
httplib2==0.19.1
idna==3.2
oauthlib==3.1.1
packaging==21.0
Pillow==8.2.0
proto-plus==1.19.0
protobuf==3.18.0
psycopg2==2.8.6
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.20
pyparsing==2.4.7
python-decouple==3.4
pytz==2021.1
requests==2.26.0
requests-oauthlib==1.3.0
rsa==4.7.2
six==1.16.0
soupsieve==2.2.1
sqlparse==0.4.1
uritemplate==3.0.1
urllib3==1.26.6
whitenoise==5.2.0

我的代码:

from Google import Create_Service
import base64
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

CLIENT_SECRET_FILE = 'client_secret.json'
API_NAME = 'gmail'
API_VERSION = 'v1'
SCOPES = ['https://mail.google.com/']

service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)

任何帮助将不胜感激

最佳答案

不再支持隐式相对导入,如 documented :

There is no longer any implicit import machinery

因此,如果 Google.py 与您粘贴的代码位于同一目录中,则必须引用它的真实位置 explicitly .

from .Google import Create_Service  # Notice the dot (.)

或者也可以是绝对路径。假设这是一个 Django 项目,那么它会是这样的:

from my_proj.Google import Create_Service  # This assumes that your file is in my_proj/my_proj/Google.py

关于python - 从谷歌导入Create_Service ModuleNotFoundError : No module named 'Google' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69252673/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com