Python pip冻结和依赖顺序
自动按字母顺序写入依赖项,如下所示:-Python pip冻结和依赖顺序,python,pip,Python,Pip,自动按字母顺序写入依赖项,如下所示:- `pip freeze > requirements.txt` 问题是pip安装-r requirements.txt(当我部署代码时,其依赖项列在requirements.txt)中)最终会失败,因为matplotlib需要先安装numpy 当我pip freeze它时,如何确保matplotlib在requirements.txt文件中的numpy之后列出?您可以尝试使用该命令 pip安装——无deps-r requirements.txt
`pip freeze > requirements.txt`
问题是pip安装-r requirements.txt
(当我部署代码时,其依赖项列在requirements.txt
)中)最终会失败,因为matplotlib需要先安装numpy
当我pip freeze
它时,如何确保matplotlib在requirements.txt
文件中的numpy之后列出?您可以尝试使用该命令
pip安装——无deps-r requirements.txt
这将安装没有依赖项的软件包,您可能会摆脱上述书面问题。对于您的情况,这并不重要,因为
pip
构建每个需求(为每个需求调用python setup.py egg\u info
),然后全部安装。对于您的特定情况,这并不重要,因为当前需要在构建matplotlib
时安装numpy
matplotlib
存在问题,他们创建了一个解决方案:
请参阅pip问题跟踪程序上本期的评论:
这个问题是重复的。注意h5py(HDF5 Python包装器)也有同样的问题
我的解决方法是将pipfreeze
的输出分成两部分:一部分是一个只包含numpy版本${numpy_REQS}
的短需求文件,另一部分是一个包含所有其他包的长需求文件${REQS}
。注意第二个grep
的-v
开关,即“反向匹配”
然后调用pip install
两次(例如,在安装虚拟环境时):
请注意,此
tee
/grep
magic组合仅适用于类Unix系统。不知道如何在Windows上实现同样的功能。可以这样使用按所需顺序包含包的文件:
# this installs numpy
pip install -r ${NUMPY_REQS}
# this installs everything else, h5py and/or matplotlib are happy
pip install -r ${REQS}
其中sorted package list.txt
包含
pip freeze -r sorted-package-list.txt > requirements.txt
注意:排序包列表.txt
文件中未包含的包附加在需求文件的末尾
示例结果:
numpy
matplotlib
你的意思是--没有dep
。但这可能会导致其他具有依赖项且需要安装这些依赖项的软件包出现问题。有关更多选项,请查看pip freeze--help
。
pip freeze -r sorted-package-list.txt > requirements.txt
numpy
matplotlib
numpy==1.14.1
matplotlib==2.2.3
## The following requirements were added by pip freeze:
pandas==0.23.4