Python生成、安装requirements.txt依赖

1,789 阅读1分钟

生成 requirements.txt

pip 方式

Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

pip listpip freeze 命令可以查看已安装的包。

pip list

➜  ~ pip list
Package           Version
----------------- ----------
amqp              2.3.2
asn1crypto        0.24.0
astroid           2.1.0
autopep8          1.4.4
bcrypt            3.1.6
billiard          3.5.0.5
certifi           2018.11.29
cffi              1.12.3
cli-helpers       1.2.0
pip list --format=freeze > requirements.txt

pip freeze

➜  ~ pip freeze
amqp==2.3.2
asn1crypto==0.24.0
astroid==2.1.0
autopep8==1.4.4
bcrypt==3.1.6
billiard==3.5.0.5
certifi==2018.11.29
cffi==1.12.3
pip freeze > requirements.txt

pipreqs

pipreqs 可以用来查找项目依赖并生成requirements.txt

pip install pipreqs
pipreqs application_path

安装 requirements.txt 中的依赖

pip install -r requirements.txt