1

I am accustomed to seeing requirements.txt that has libraries optionally with an associated [minimum] version.

pandas==1.0.4

In an existing project I am now working on instead we have library entries like this:

argcomplete==1.12.3 \
    --hash=sha256:291f0beca7fd49ce285d2f10e4c1c77e9460cf823eef2de54df0c0fec88b0d81 \
    --hash=sha256:2c7dbffd8c045ea534921e63b0be6fe65e88599990d8dc408ac8c542b72a5445
asgiref==3.4.1; python_version >= "3.6" \
    --hash=sha256:ffc141aa908e6f175673e7b1b3b7af4fdb0ecb738fc5c8b88f69f055c2415214 \
    --hash=sha256:4ef1ab46b484e3c706329cedeff284a5d40824200638503f5768edb6de7d58e9
certifi==2021.5.30; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.6" \
    --hash=sha256:50b1e4f8446b06f41be7dd6338db18e0990601dce795c2b1686458aa7e8fa7d8 \
    --hash=sha256:2bbf76fd432960138b3ef6dda3dde0544f27cbf8546c458e60baf371917ba9ee
cffi==1.14.6; python_version >= "3.6" \
    --hash=sha256:22b9c3c320171c108e903d61a3723b51e37aaa8c81255b5e7ce102775bd01e2c \
    --hash=sha256:f0c5d1acbfca6ebdd6b1e3eded8d261affb6ddcf2186205518f1428b8569bb99 \
    --hash=sha256:99f27fefe34c37ba9875f224a8f36e31d744d8083e00f520f133cab79ad5e819 \
    --hash=sha256:55af55e32ae468e9946f741a5d51f9896da6b9bf0bbdd326843fec05c730eb20 \

The project does use poetry - which might have been the generator of the file? How did it generate this file and how can I add my new dependency - which is pytest 7.0.0 ?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560
  • 1
    `poetry export -f requirements.txt --output requirements.txt` https://python-poetry.org/docs/cli/#options-11 -- can also be done with _pip_ and I think with other tools as well – sinoroc Feb 11 '22 at 11:39
  • @sinoroc. I want to add the new requirement - how do I do that in this file with all those hash codes? – WestCoastProjects Feb 11 '22 at 18:32
  • Depends what tools you have at your disposal and what your workflow is. With _pip_, first `python -m pip install 'pandas==1.0.4'` and then `python -m pip freeze`. With _poetry_, first `poetry add 'pandas==1.0.4'` and then `poetry export`. – sinoroc Feb 11 '22 at 18:48
  • @sinoroc the `poetry add` is the key - can you make that an answer? – WestCoastProjects Feb 11 '22 at 20:31

1 Answers1

4

First add the library with with Poetry CLI's add command:

poetry add 'pandas==1.0.4'

or any other version constraints than ==1.0.4 that you might want.

Then generate the requirements file with its export command:

poetry export --format requirements.txt --output requirements.txt
sinoroc
  • 18,409
  • 2
  • 39
  • 70