生成requirements.txt的方法

生成requirements.txt的方法

第一种 是使用freeze

# 安装
pip install freeze
#生成requirements文件
pip freeze > requirements.txt

此方法是将此环境所有的依赖包全部生成加入,及时在当前项目中未成使用的模块,

第二种 是使用pipreqs

# 安装
pip install pipreqs
# 在项目根目录下执行命令
pipreqs . --encoding=utf8 --force
or
pipreqs ./ --encoding=utf8 --force
# 相关参数
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.

此方法将当前环境所用的模块生成加入,未使用的模块则不会加入到requirements文件。
如果想查看源码,可以通过github地址为: https://github.com/bndr/pipreqs 进行查看
另外 其中的–encoding=utf8 为编码设置(此处使用的是utf8编码),有的系统可能会报UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xae in position 406: illegal multibyte sequence 的错误。可根据情况进行设置

安装requirements.txt方法

pip install -r requirements.txt
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值