How can I get a list of locally installed Python modules?

前端 未结 30 2175
庸人自扰
庸人自扰 2020-11-22 04:32

I would like to get a list of Python modules, which are in my Python installation (UNIX server).

How can you get a list of Python modules installed in your computer?

30条回答
  •  礼貌的吻别
    2020-11-22 05:08

    There are many ideas, initially I am pondering on these two:

    pip

    cons: not always installed

    help('modules')

    cons: output to console; with broken modules (see ubuntu...) can segfault

    I need an easy approach, using basic libraries and compatible with old python 2.x

    And I see the light: listmodules.py

    Hidden in the documentation source directory in 2.5 is a small script that lists all available modules for a Python installation.

    Pros:

    uses only imp, sys, os, re, time

    designed to run on Python 1.5.2 and newer

    the source code is really compact, so you can easy tinkering with it, for example to pass an exception list of buggy modules (don't try to import them)

提交回复
热议问题