Python 生成项目的 requirements.txt 文件

pip freeze

它生成的 requirements.txt 文件包含当前环境的完全列表,不相关的依赖包也会包含进来。

pipreqs

pip install pipreqs
pipreqs --force <project-path>

只会包含项目 imports 的包,包含列表不是很完全

pigar

pip install pigar

输出信息比 pipgreqs 详细

  -h, --help          show this help message and exit
  -v, --version       show pigar version information and exit
  -u, --update        update database, use it when pigar failed you, exit when
                      action done
  -s NAME [NAME ...]  search package name by import name, use it if you do not
                      know import name come from which package, exit when
                      action done
  -c [PATH]           check requirements for the latest version. If file path
                      not given, search *requirements.txt in current
                      directory, if not found, generate file requirements.txt,
                      exit when action done
  -l LOG_LEVEL        show given level log messages, argument can be (ERROR,
                      WARNING, INFO), case-insensitive
  -i DIR [DIR ...]    given a list of directory to ignore, relative directory,
                      *used for* -c and default action
  -p SAVE_PATH        save requirements in given file path, *used for* default
                      action
  -P PROJECT_PATH     project path, which is directory, *used for* default
                      action
    原文作者:l1xnan
    原文地址: https://segmentfault.com/a/1190000008552604
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞