python3.13 安装 cos-python-sdk-v5 出现 AttributeError: module ‘pkgutil‘ has no attribute ‘ImpImporter‘.
【代码】python3.13 安装 cos-python-sdk-v5 出现 AttributeError: module ‘pkgutil‘ has no attribute ‘ImpImporter‘.
·
原因
- 由于 Python 版本兼容性问题导致的。ImpImporter 在较新的 Python 版本(3.12+)中已被移除,而某些依赖库可能还在尝试使用这个已被废弃的模块。
方案一,安装腾讯的所有sdk库(失败)
- pip install --upgrade tencentcloud-sdk-python,使用新库执行,导入不了这个库
from tencentcloud.cos.v20180523 import cos_client, models
ModuleNotFoundError: No module named 'tencentcloud.cos'
- 检查按照文件,发现没有cos这个库
# 查看安装路径
python -c "import tencentcloud; print(tencentcloud.__file__)"
# 检查是否包含 cos 模块
ls $(python -c "import tencentcloud; print(tencentcloud.__path__[0])")/cos
方案二,直接修改报错代码位置
- 修改保存地方,替换register_finder(zipimport.zipimporter, find_on_path),有两个位置要修改,第2191行和2349行
vim /Users/jtserver/.virtualenvs/noah/lib/python3.13/site-packages/pkg_resources/__init__.py
# register_namespace_handler(pkgutil.ImpImporter, file_ns_handler)
register_finder(zipimport.zipimporter, find_on_path)
参考
更多推荐
所有评论(0)