高效工具-requirement生成和配置

项目需求

在使用项目的过程中,发现大佬们的项目中自带requirement.txt文件,可以加快项目环境部署的节奏。

自己目前具备环境部署的需要,需要能够快速方便的部署环境,方案1是生成requirement.txt

requirement生成方法

简要介绍

  • freeze是python自带的pip 模块下的指令,pipreqs 模块需要安装后才能使用
  • pip freeze只能保存使用pip install指令安装在环境中的包
  • pip freeze 会保存项目中没有使用过的包(除非使用virtualenv)
  • 因此一般安装所有模块使用pip freeze方法,精简安装版使用pipreqs方法

pip freeze方法

官方介绍文档

pip freeze [options]
--r, --requirement <file>
Use the order in the given requirements file and its comments when generating output. This option can be used multiple times.

-l, --local
If in a virtualenv that has global access, do not output globally-installed packages.

--user
Only output packages installed in user-site.

--path <path>
Restrict to the specified installation path for listing packages (can be used multiple times).

--all
Do not skip these packages in the output: setuptools, distribute, wheel, pip

--exclude-editable
Exclude editable package from output.

--exclude <package>
Exclude specified package from the output

使用示范

pip freeze > requirements_whole.txt

pipreqs 方法

官方介绍文档

Usage:
    pipreqs [options] <path>

Options:
    --use-local           Use ONLY local package info instead of querying PyPI
    --pypi-server <url>   Use custom PyPi server
    --proxy <url>         Use Proxy, parameter will be passed to requests library. You can also just set the
                          environments parameter in your terminal:
                          $ export HTTP_PROXY="http://10.10.1.10:3128"
                          $ export HTTPS_PROXY="https://10.10.1.10:1080"
    --debug               Print debug information
    --ignore <dirs>...    Ignore extra directories
    --encoding <charset>  Use encoding parameter for file open
    --savepath <file>     Save the list of requirements in the given file
    --print               Output the list of requirements in the standard output
    --force               Overwrite existing requirements.txt
    --diff <file>         Compare modules in requirements.txt to project imports.
    --clean <file>        Clean up requirements.txt by removing modules that are not imported in project.
    --no-pin              Omit version of output packages.

使用示范

pipreqs ./ --encoding=utf8 --use-local --force

requirement使用方法

在利用上面两种方法中的一种方法生成requirement后,可以直接利用requirements安装项目所需要的包

pip install -r requirements.txt
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

儒雅的钓翁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值