PyInstaller打包Google Calendar API项目时出现AttributeError问题求助
解决PyInstaller打包Google Calendar API应用时的
AttributeError问题 遇到打包后运行exe出现AttributeError: module 'google.auth.credentials' has no attribute 'CredentialsWithTokenUri'的问题,可尝试以下方案:
添加隐式导入配置
PyInstaller可能未自动识别google.auth模块的内部子类,需手动指定:- 生成.spec配置文件:
pyi-makespec your_app.py - 打开生成的.spec文件,找到
hiddenimports参数,补充内容:hiddenimports=['google.auth.credentials', 'google.oauth2.credentials'] - 基于.spec文件重新打包:
pyinstaller your_app.spec
- 生成.spec配置文件:
升级依赖包
版本不兼容可能引发该问题,执行命令更新相关依赖:pip install --upgrade google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client pyinstaller确保打包环境一致性
确认打包使用的Python环境(如虚拟环境)与开发环境完全一致,避免依赖版本混乱,激活对应环境后再执行打包命令。手动补充缺失文件
若以上方法无效,找到Python site-packages目录下的google/auth/credentials.py文件,将其复制到exe所在目录的google/auth子文件夹中(无该目录则手动创建)。
内容的提问来源于stack exchange,提问作者Dinosaur
相关产品推荐
相关产品推荐

