You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Python Anywhere中用Flask+gspread遇‘google.auth.api_key缺失’错误求助

File "/home/vishal6596/mysite/flask_app.py", line 7, in
import gspread
File "/home/vishal6596/.local/lib/python3.10/site-packages/gspread/init.py", line 7, in
from .auth import (
File "/home/vishal6596/.local/lib/python3.10/site-packages/gspread/auth.py", line 14, in
from google.auth.api_key import Credentials as APIKeyCredentials
ModuleNotFoundError: No module named 'google.auth.api_key'

解决gspread导入错误的可行方案
  • 升级google-auth库:google.auth.api_key模块是较新版本的google-auth才引入的,Python Anywhere上的版本可能过低。执行对应Python3.10的升级命令:

    pip3.10 install --upgrade google-auth
    
  • 同步依赖版本:本地PyCharm能正常运行,说明本地依赖版本兼容。在本地执行pip freeze > requirements.txt生成依赖清单,然后在Python Anywhere上运行:

    pip3.10 install -r requirements.txt
    

    确保所有依赖包版本和本地完全一致。

  • 检查安装环境与路径:确认Python Anywhere的Flask运行环境使用的是Python3.10。如果使用了虚拟环境,先激活再安装依赖:

    source /home/vishal6596/your_virtual_env/bin/activate
    pip install --upgrade gspread google-auth
    

    未使用虚拟环境的话,添加--user参数确保安装到当前用户的Python3.10路径下:

    pip3.10 install --user --upgrade gspread google-auth
    
  • 重装关联依赖:直接卸载并重新安装所有相关包,修复可能的损坏或缺失:

    pip3.10 uninstall -y gspread google-auth google-auth-oauthlib
    pip3.10 install gspread google-auth google-auth-oauthlib
    

内容的提问来源于stack exchange,提问作者VISHAL SHARMA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 07:43:31