Secret Recipes of the Python Ninja
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Manually create requirements.txt by typing in the packages to include in the project. The following is an example from https://pip.pypa.io/en/latest/reference/pip_install/#requirements-file-format:

  1. Alternatively, run pip freeze > requirements.txt. This automatically directs the currently installed packages to a properly formatted requirements file.
  2. To implement hash-checking mode, simply include the digest with the package name in the requirements file, demonstrated below:
      FooProject == 1.2 --hash=sha256:<hash_digest>

Note: Supported hash algorithms include: md5, sha1, sha224, sha384, sha256, and sha512.

  1. If there are module conflicts, or special versioning is needed, provide the first module required:
      m1
  1. Indicate the second module, but ensure the version installed pre-dates the known bad version:
      m2<1.7
  1. Provide the third module, ensuring it is at least equal to the minimum version required, but no greater than the maximum version that can be used:
     m3>=1.5, <=2.0

While the preceding screenshot shows some version specifier requirements, here is an example showing some of the different ways to specify module versions in requirements.txt:

        flask
flask-pretty == 0.2.0
flask-security <= 3.0
flask-oauthlib >= 0.9.0, <= 0.9.4