执行poetry add时出现'HttpResponse' object has no attribute 'strict'的问题排查
Poetry安装Pandas时报错'HttpResponse' object has no attribute 'strict'的原因及解决方法
可能原因
- Poetry版本过旧:旧版Poetry依赖的requests/urllib3版本与当前系统中高版本requests不兼容——高版本requests的
HttpResponse对象已移除strict属性,导致Poetry调用该属性时触发错误。 - 全局环境污染:直接在全局Python环境运行Poetry,而全局环境中安装的requests等库版本不符合Poetry的依赖要求,引发属性调用冲突。
- 虚拟环境未激活:执行
poetry add时没激活Poetry自动创建的虚拟环境,导致使用了外部环境的冲突库。
解决方法
1. 更新Poetry到最新版本
新版本通常会修复依赖兼容性问题,执行以下命令更新:
poetry self update
Windows用户(PowerShell)可使用:
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
2. 激活Poetry虚拟环境后操作
先激活Poetry为项目创建的专属虚拟环境:
- Linux/macOS:
source $(poetry env info --path)/bin/activate
- Windows(PowerShell):
& (poetry env info --path)\Scripts\Activate.ps1
激活成功后再执行poetry add pandas。
3. 重建Poetry虚拟环境
如果原有虚拟环境已被污染,直接重置:
poetry env remove python poetry install poetry add pandas
4. 临时指定兼容的requests版本
若暂时无法更新Poetry,可先在pyproject.toml中添加兼容的requests版本:
[tool.poetry.dependencies] python = "^3.8" # 替换为你的Python实际版本 requests = "2.28.2"
执行poetry install安装依赖后,再运行poetry add pandas。
内容的提问来源于stack exchange,提问作者KansaiRobot
相关产品推荐
相关产品推荐

