0

I'm following the without setup.py example in the pip-tools documentation at https://github.com/jazzband/pip-tools#without-setuppy

What I did is I have this as my requirements.in

# To update requirements.txt, run:
#
#    pip-compile requirements.in
#
# To install in localhost, run:
#
#    pip-sync requirements.txt
#

django==3.2.5  # https://www.djangoproject.com/

psycopg2-binary==2.8.6 # https://github.com/psycopg/psycopg2

Then I have this as prod-requirements.in

# To update prod-requirements.txt, run:
#
#    pip-compile prod-requirements.in
#
# To install in prod, run:
#
#    pip-sync requirements.txt prod-requirements.txt
#

-c requirements.txt

gunicorn==20.1.0  # https://github.com/benoitc/gunicorn

At the production I run

$ pip-sync requirements.txt prod-requirements.txt

My question is how do I enforce a minimum python version? I only want to set up to the minor python version. meaning I want a way to pin to python 3.8 for example.

Can I do that with pip-tools? Do I need to choose the setup.py method?

I prefer to do it with just the requirements.in method as I'm most familiar with it

sinoroc
  • 18,409
  • 2
  • 39
  • 70
Kim Stacks
  • 10,202
  • 35
  • 151
  • 282
  • 2
    Why do you want to limit Python? Just document (in the README or whatever) what Python versions should be used. Isn't it enough? I think that is how it is typically done for Django applications, but I am not sure to be honest. -- By the way, just to make sure: we are talking about an application here (and not a library), correct? And how do you want to publish and/or deploy? – sinoroc Jan 29 '22 at 17:26

1 Answers1

1

As far as I know, you can not specify constraints on versions of the Python interpreter via a requirements.txt file.

Other toolings allow to specify version specifiers on the Python interpreter.

For example via the Requires-Python packaging core metadata field, which is supported by all Python packaging build back-ends I know of, including setuptools via its python_requires parameter and also flit, hatch, pdm, poetry to name a few. Some of them rely on the (new) PEP 621 standard and its requires-python field.

You might also look into pipenv, which might be good if you are not interested in really "packaging" your application (i.e. you are not planning to build a wheel and upload it to a package index server like PyPI).

sinoroc
  • 18,409
  • 2
  • 39
  • 70
  • if i want to use pip-tools and for django projects, AND still limit python versions, then i have no choice but to use setup.py do i? – Kim Stacks Jan 29 '22 at 16:41
  • I think i have come to the acceptance of using setup.py. I am resisting it too much. nevertheless i will award you the full 100 points. I won't mark as answer tho. there's a time limit so i can only award bounty 9 hrs later. will come back to do so – Kim Stacks Jan 30 '22 at 08:40
  • You probably do not have to use [_setuptools_](https://pypi.org/project/setuptools/). You can probably use any other build back-end: [_flit_](https://pypi.org/project/flit/), [_hatch_](https://pypi.org/project/hatch/), [_pdm_](https://pypi.org/project/pdm/), [_poetry_](https://pypi.org/project/poetry/) to name a few. Unless maybe _pip-tools_ is only compatible with _setuptools_, I don't know. – sinoroc Jan 30 '22 at 12:05