首页 > 解决方案 > 列出一个项目导入的所有python模块

问题描述

我在 python=3.6 上运行我的项目,我想列出这个项目/repo/目录中存在的 python 脚本导入的所有模块,以便我可以构建一个项目特定的需求文件以供将来使用。帮助我编写一个脚本来遍历目录树以列出模块或任何可用的 python 模块。

标签: python-3.xlinuxshellpython-module

解决方案


I came across the pipreqs package, which generates a requirement.txt file based on the import statements of the project.

Installation:

pip install pipreqs

Usage:

pipreqs /path/to/project

pipreqs will automatically generate a requirements.txt file in root folder of your project.

Limitation: Pipreqs uses imports of projects to generate a requirements.txt file. So, it is very important to note that, pipreqs will not include the plugins required for specific projects. You need to add plugins information manually in a requirement.txt


推荐阅读