有没有可能的方法来获取系统上所有可能的 python 模块的列表。例如,在 IDLE 中,您可以执行类似操作help('modules')并获取已安装软件包的排序列表。但我想要的是从 python 程序内部以编程方式收集列表。就像是:possible_packages = ["os","pty","psutil",..]从那里能够解析该列表。我怎样才能在 python 程序中做到这一点?
1 回答

BIG阳
TA贡献1859条经验 获得超6个赞
您可以使用pkgutil.walk_packages:
from pkgutil import walk_packages
possible_packages = [module for _, module, _ in walk_packages()]
添加回答
举报
0/150
提交
取消