查看python第三方库的依赖
Posted Circle-C
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查看python第三方库的依赖相关的知识,希望对你有一定的参考价值。
背景
平时开发直接pip install 命令即可安装所需的python第三方库,但是部署项目到生产环境时,可能服务器并不能 访问外网,pip install没办法使用,只能将第三方包打包,离线安装,这就涉及到要打包的第三方库及其所依赖的库.
方法1
pip show 库名称
例如查看pandas库及其依赖:
D:\\Program\\Project\\streamlit>pip show pandas Name: pandas Version: 1.2.4 Summary: Powerful data structures for data analysis, time series, and statistics Home-page: https://pandas.pydata.org Author: None Author-email: None License: BSD Location: d:\\program\\anaconda3\\lib\\site-packages Requires: python-dateutil, numpy, pytz Required-by: tabula-py, streamlit, statsmodels, seaborn, altair
可以看到pandas库依赖python-dateutil、numpy、pytz这三个库,也就是要使用pandas必须先安装这三个库.但是可能这三个库也存在依赖库,所以这种方式并不能全部显示所有依赖。
方法2
使用pipdeptree
首先安装pipdeptree库:
pip install pipdeptree
然后使用命令:pipdeptree -p 库名
还以pandas为例:
D:\\Program\\Project\\streamlit>pipdeptree -p pandas Warning!!! Possibly conflicting dependencies found: * -yspark==3.2.0 - py4j [required: ==0.10.9.2, installed: 0.10.9] * anaconda-project==0.9.1 - ruamel-yaml [required: Any, installed: ?] * autopep8==1.5.6 - pycodestyle [required: >=2.7.0, installed: 2.6.0] * conda-repo-cli==1.0.4 - pathlib [required: Any, installed: ?] * flake8==3.9.0 - pycodestyle [required: >=2.7.0,<2.8.0, installed: 2.6.0] - pyflakes [required: >=2.3.0,<2.4.0, installed: 2.2.0] * pylint==2.7.4 - astroid [required: >=2.5.2,<2.7, installed: 2.5] * QDarkStyle==2.8.1 - helpdev [required: >=0.6.10, installed: ?] * spyder==4.2.5 - pyqtwebengine [required: <5.13, installed: ?] - pyqt5 [required: <5.13, installed: ?] ------------------------------------------------------------------------ pandas==1.2.4 - numpy [required: >=1.16.5, installed: 1.20.1] - python-dateutil [required: >=2.7.3, installed: 2.8.1] - six [required: >=1.5, installed: 1.15.0] - pytz [required: >=2017.3, installed: 2021.1]
可以看到pandas依赖三个库,其中ython-dateutil库还依赖six库,可以详细查看到依赖结构,推荐使用该方式。
以上是关于查看python第三方库的依赖的主要内容,如果未能解决你的问题,请参考以下文章