[英]Creating a requirements.txt without development dependencies
In development often additional packages are needed which I have installed in my venv
, which are not needed in production contrary to other packages I also installed in my venv
.在开发中,通常需要我在venv
安装的其他软件包,与我也在venv
安装的其他软件包相反,生产中不需要这些软件包。 What's the cleanest way to produce a requirements.txt
which does have all the requirements except the once I only need in development (like mypy
or autopep8
)生成requirements.txt
的最干净的方法是什么,除了我只在开发中需要的一次(如mypy
或autopep8
)之外,它确实具有所有要求
This answer shows how to do it but the method is very cumbersome.这个答案显示了如何做到这一点,但方法非常麻烦。
I'd recommend using pip-compile
, from https://pypi.org/project/pip-tools/ .我建议使用来自https://pypi.org/project/pip-tools/ 的pip-compile
。
This lets you define an "in" file, requirements.in
, which just lists your top-level dependencies, eg:这允许您定义一个“in”文件, requirements.in
,它只列出您的顶级依赖项,例如:
requirements.in
: requirements.in
:
flask
Then you generate the requirements.txt
with pip-compile
:然后你用pip-compile
生成requirements.txt
:
$ pip-compile --output-file=requirements.txt requirements.in
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file=requirements.txt requirements.in
#
click==7.1.2 # via flask
flask==1.1.2 # via -r requirements.in
itsdangerous==1.1.0 # via flask
jinja2==2.11.2 # via flask
markupsafe==1.1.1 # via jinja2
werkzeug==1.0.1 # via flask
Then you can have separate .in
/ .txt
files for different environments, like test.in
/ test.txt
.然后你可以为不同的环境创建单独的.in
/ .txt
文件,比如test.in
/ test.txt
。
And finally, you can recursively include multiple requirements files, eg最后,您可以递归地包含多个需求文件,例如
dev-requirements.txt
: dev-requirements.txt
:
-r requirements.txt
-r test.txt
-r lint.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.