理解Pipfile vs. setup.py || applications vs. libraries

  • requirements.txt

    requirements file format

    requirement specifiers

    PEP 508 – Dependency specification for Python Software Packages

    Requirements files are files containing a list of items to be installled using pip install like so :

    pip install -r requirements.txt

    Logically, a Requirements file is just a list of pip install arguments placed in a file.

    There are 4 common uses of Requirements files :

    1. Requirements files are used to hold the result from pip freeze for the purpose of achieving repeatable installations. In this case, your requirement file contains a pinned version of everything that was installed when pip freeze was run.

      pip freeze > requirements.txt
      pip install -r requirements.txt
      
    2. Requirements files are used to force pip to properly resolve dependencies.

    3. Requirements files are used to force pip to install an alternate version of a subdependency

    4. Requirements files are used to override a dependency with a local patch that lives in version control.

  • Pipfile

    Pipfile(GitHub) and its sister Pipfile.lock are a replacement for the existing standard pip’s requirements.txt file.

    pip install -r requirements.txt
    pip install -p Pipfile # 安装
    pip freeze -p Pipfile # 生成
    
  • distinction between applications and libraries

  • Libraries

    Libraries provide reusable functionality to other libraries and applications (let’s use the umbrella term project here). They are required to work alongside other libraries, all with their own set of sub-dependencies. They defines abstract dependencies. To avoid version conflicts in sub-dependencies of different libraries within a project, libraries shouyld never ever pin dependency versions. Although they may specify lower or (less frequently) upper bounds, if they rely on some specific feature/fix/bug. Library dependencies are specified via install_requires in setup.py.

  • Applications

    Libraries are ultimately meant to be used in some application. Applications are different in that they usually are not depended on by other projects. They are meant to be deployed into some specific environment and only then should the exact versions of all their dependencies and sub-dependencies be made concrete.

  • To summarize
    • For libraries, define abstract dependencies via install_requires in setup.py. The decision of which version exactly to be installed and where to obtain that dependency is not yours to make.
    • For applications, define dependencies and where to get them in the Pipfile and use this file to update the set of concrete dependencies in Pipfile.lock. This file defines a specific idempotent environment that is known to work for your project.
    • Pipfile and Pipenv can be used to define a development or test environment.
  • References

  1. Pipfile vs setup.py
  2. pip 与 Pipfile
  3. Ken Reitz : Announcing Pipenv
  4. How are Pipfile and Pipfile.lock used?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值