python - 为什么 pip install 有时会选择不兼容的版本?
问题描述
在我的 python 包 htrest (https://pypi.org/project/htrest/)中,我有以下要求:
requirements = [
'htheatpump==1.2.1',
'Flask==1.1.1',
'flask-restx==0.1.1',
'Flask-BasicAuth==0.2.0',
# put package requirements here
]
当我使用它安装它时pip install htrest
,有时会失败并显示以下消息:
flask-restx 0.1.1 has requirement werkzeug<=0.16.1, but you'll have werkzeug 1.0.0 which is incompatible.
看起来 pip 是因为( )werkzeug==1.0.0
的要求而选择的Flask
Werkzeug>=0.15
Collecting Werkzeug>=0.15 (from Flask==1.1.1->htrest)
Using cached https://files.pythonhosted.org/packages/ba/a5/d6f8a6e71f15364d35678a4ec8a0186f980b3bd2545f40ad51dd26a87fb1/Werkzeug-1.0.0-py2.py3-none-any.whl
虽然flask-restx
需要werkzeug<=0.16.1
.
另一方面,有时 pip 会选择合适的werkzeug
( 0.16.1
) 版本:
Collecting werkzeug<=0.16.1 (from flask-restx==0.1.1->htrest)
Using cached https://files.pythonhosted.org/packages/c2/e4/a859d2fe516f466642fa5c6054fd9646271f9da26b0cac0d2f37fc858c8f/Werkzeug-0.16.1-py2.py3-none-any.whl
来满足 和 的Flask
要求 flask-restx
。
谁能解释一下原因以及如何解决这个问题?
问候,丹尼尔。
解决方案
默认情况下,该pip install <package_name>
命令总是查找最新版本的软件包并安装它。同时,它还会搜索包元数据中列出的最新版本的依赖项并安装这些依赖项,以确保包具有所需的所有要求。
如果要安装以前的版本,则必须指定此版本。本文提供了有关 pip 工作原理的完整详细信息
在您的情况下,您应该这样进行:
pip3 uninstall Werkzeug # uninstalling the current Werkzeug
pip3 install Werkzeug==0.16.1 # install specific version of Werkzeug
推荐阅读
- mysql - mysql查询加入,比较两个表并返回第一个表中的所有记录
- html - Flask-如何修复 html 中的 img '404 图片未找到'
- javascript - 我想在右上角显示每个日期的值,它的标题
- android - 我们可以在一个 xml 文件中创建多个形状并将它们指向这个单个文件吗?
- c++ - 如何从 github 为 C++ 项目正确安装第三方库?
- python - 协议中的 CRC 计算不正确。一种是使用zlib实现的,另一种是在函数中计算的
- python-3.x - 功能完成后如何销毁顶层窗口?
- cgal - CGAL:join_facet() 对循环器的真正作用是什么?
- java - 如何打印、排序和获取高于 90 的温度
- java - 如何在 Android Studio 3.4 中复制和重命名项目?