[英]Reducing requirements.txt
Is there a way to reduce my requirements.txt I switched to Python a year ago and back then I did not completely understand how things work.有没有办法减少我的requirements.txt 我一年前改用Python,那时我还没有完全理解事情是如何工作的。 So when I needed to create requirements.txt I just did a pip freeze and copy passed all the requirements.
所以当我需要创建 requirements.txt 时,我只是做了一个 pip freeze 并复制通过了所有的要求。 Today I know that I don't need them all just top-level that import other requirements is there a way to achieve it?
今天我知道我不需要它们都只是顶级的导入其他要求有没有办法实现它?
There's a few options.有几个选项。
If you are using pip
in your project, you can appreciate pip-tools .如果您在项目中使用
pip
,您可以欣赏pip-tools 。 First put your requirements manually into requirements.in
, and then with pip-compile
you can generate the final requirements.txt
with all dependencies.首先将您的需求手动放入
requirements.in
,然后使用pip-compile
您可以生成包含所有依赖项的最终requirements.txt
。 Let's say dependencies of your project are Django and Ansible.假设您的项目的依赖项是 Django 和 Ansible。 You put them into
requirements.in
like this:您将它们放入
requirements.in
如下所示:
# requirements.in
django
ansible
and then run pip-compile
to get the whole dependency graph:然后运行
pip-compile
来获取整个依赖图:
$ pip-compile requirements.in
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
ansible==2.9.12 # via -r requirements.in
cffi==1.14.2 # via cryptography
cryptography==3.1 # via ansible
django==1.11.29 # via -r requirements.in
jinja2==2.11.2 # via ansible
markupsafe==1.1.1 # via jinja2
pycparser==2.20 # via cffi
pytz==2020.1 # via django
pyyaml==5.3.1 # via ansible
six==1.15.0 # via cryptography
If you are using Poetry , then you can keep adding the dependencies via poetry add
, and eventually export them if needed.如果您正在使用Poetry ,那么您可以通过Poetry
poetry add
继续添加依赖poetry add
,并在需要时最终导出它们。 Otherwise you can skip the export step, as poetry can generate the package for distributing for you via poetry build
:否则,您可以跳过导出步骤,因为诗歌可以生成用于通过
poetry build
分发的包:
$ poetry add django
Using version ^3.1 for django
Updating dependencies
Resolving dependencies... (1.4s)
Writing lock file
Package operations: 3 installs, 0 updates, 0 removals
- Installing asgiref (3.2.10)
- Installing sqlparse (0.3.1)
- Installing django (3.1)
You can find all dependencies in pyproject.toml
.您可以在
pyproject.toml
找到所有依赖pyproject.toml
。 In case you need to export it into requirements.txt
:如果您需要将其导出到
requirements.txt
:
$ poetry export -f requirements.txt -o requirements.txt --without-hashes
I'm using --without-hashes
, since AppEngine has problem with it我正在使用
--without-hashes
,因为 AppEngine 有问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.