查看python第三方库所依赖的包

        平常在项目开发中,我们可以很容易的通过pip install packname安装python第三方包,但在项目上线前,我们该如何将该项目所需要的第三方包及其依赖包放到python虚拟开发环境中呢?

        例如:我在环境中装了python的celery库,现在我想把celery包及其安装所依赖的包导出来,以便可以放在另一台机器上(无外网访问权限)的python虚拟环境直接使用

方法1只列出了celery包的主依赖包pytz, billiard, kombu, vine,

方法2列出了celery包的主依赖包与各主依赖包所依赖的包,但看起来比较乱

方法3以树结构形式列出了celery包的主依赖包与各主依赖包的子依赖包,可读性好,一目了然,建议使用此法。

方法1:

(poc)[root@zq ~]# pip show celery

Name: celery
Version: 4.3.0
Location: /opt/poc/lib/python2.7/site-packages/celery-4.3.0-py2.7.egg
Requires: pytz, billiard, kombu, vine: #主依赖项,这些主依赖项还依赖于其它包

  方法2:

(poc)[root@zq ~]# pip install celery
Requirement already satisfied (use --upgrade to upgrade): celery in /opt/poc/lib/python2.7/site-packages/celery-4.3.0-py2.7.egg
Requirement already satisfied (use --upgrade to upgrade): pytz>dev in /opt/poc/lib/python2.7/site-packages (from celery)
Requirement already satisfied (use --upgrade to upgrade): billiard<4.0,>=3.6.0 in /opt/poc/lib/python2.7/site-packages/billiard-3.6.1.0-py2.7.egg (from celery)
Requirement already satisfied (use --upgrade to upgrade): kombu<5.0,>=4.4.0 in /opt/poc/lib/python2.7/site-packages/kombu-4.6.6-py2.7.egg (from celery)
Requirement already satisfied (use --upgrade to upgrade): vine>=1.3.0 in /opt/poc/lib/python2.7/site-packages (from celery)
Requirement already satisfied (use --upgrade to upgrade): amqp<2.6,>=2.5.2 in /opt/poc/lib/python2.7/site-packages/amqp-2.5.2-py2.7.egg (from kombu<5.0,>=4.4.0->celery)
Requirement already satisfied (use --upgrade to upgrade): importlib-metadata>=0.18 in /opt/poc/lib/python2.7/site-packages/importlib_metadata-0.23-py2.7.egg (from kombu<5.0,>=4.4.0->celery)
Requirement already satisfied (use --upgrade to upgrade): configparser>=3.5 in /opt/poc/lib/python2.7/site-packages/configparser-4.0.2-py2.7.egg (from importlib-metadata>=0.18->kombu<5.0,>=4.4.0->celery)
Requirement already satisfied (use --upgrade to upgrade): contextlib2 in /opt/poc/lib/python2.7/site-packages/contextlib2-0.6.0.post1-py2.7.egg (from importlib-metadata>=0.18->kombu<5.0,>=4.4.0->celery)
Requirement already satisfied (use --upgrade to upgrade): pathlib2 in /opt/poc/lib/python2.7/site-packages/pathlib2-2.3.5-py2.7.egg (from importlib-metadata>=0.18->kombu<5.0,>=4.4.0->celery)
Requirement already satisfied (use --upgrade to upgrade): zipp>=0.5 in /opt/poc/lib/python2.7/site-packages/zipp-0.6.0-py2.7.egg (from importlib-metadata>=0.18->kombu<5.0,>=4.4.0->celery)
Requirement already satisfied (use --upgrade to upgrade): scandir in /opt/poc/lib/python2.7/site-packages (from pathlib2->importlib-metadata>=0.18->kombu<5.0,>=4.4.0->celery)
Requirement already satisfied (use --upgrade to upgrade): six in /opt/poc/lib/python2.7/site-packages (from pathlib2->importlib-metadata>=0.18->kombu<5.0,>=4.4.0->celery)
Requirement already satisfied (use --upgrade to upgrade): more-itertools in /opt/poc/lib/python2.7/site-packages (from zipp>=0.5->importlib-metadata>=0.18->kombu<5.0,>=4.4.0->celery)
Cleaning up...

 

  方法3:与方法2的结果一致   
 推荐使用方法3

(poc)[root@zhangqiang ~]# pipdeptree -p celery   #能显示所有的依赖包及其子包
Warning!!! Possibly conflicting dependencies found:
* arrow==0.15.4
- backports.functools-lru-cache [required: >=1.2.1, installed: ?]
* cryptography==2.4.2
- idna [required: >=2.1, installed: ?]
* cffi==1.12.3
- pycparser [required: Any, installed: ?]
------------------------------------------------------------------------
celery==4.3.0
  - billiard [required: >=3.6.0,<4.0, installed: 3.6.1.0]
  - kombu [required: >=4.4.0,<5.0, installed: 4.6.6]
    - amqp [required: >=2.5.2,<2.6, installed: 2.5.2]         #kombu的依赖项
      - vine [required: >=1.1.3,<5.0.0a1, installed: 1.3.0]
    - importlib-metadata [required: >=0.18, installed: 0.23]
      - configparser [required: >=3.5, installed: 4.0.2]
      - contextlib2 [required: Any, installed: 0.6.0.post1]
      - pathlib2 [required: Any, installed: 2.3.5]
        - scandir [required: Any, installed: 1.10.0]
        - six [required: Any, installed: 1.10.0]
      - zipp [required: >=0.5, installed: 0.6.0]
        - more-itertools [required: Any, installed: 4.2.0]
          - six [required: >=1.0.0,<2.0.0, installed: 1.10.0]
  - pytz [required: >dev, installed: 2017.2]
  - vine [required: >=1.3.0, installed: 1.3.0]

 

 

 

 

 

 

    原文作者:青霄
    原文地址: https://blog.csdn.net/leiwuhen92/article/details/104017648
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞