Skip to content

Commit 645e936

Browse files
jwodderJon Wayne Parrott
authored andcommitted
Document python_requires (pypa#338)
1 parent cc80122 commit 645e936

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

scripts/linkmonitor/inventory.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@
173173
tutorials/distributing-packages.html#packages, tutorials/distributing-packages.html#packaging-and-distributing-projects,
174174
tutorials/distributing-packages.html#packaging-your-project, tutorials/distributing-packages.html#platform-wheels,
175175
tutorials/distributing-packages.html#pre-release-versioning, tutorials/distributing-packages.html#pure-python-wheels,
176-
tutorials/distributing-packages.html#readme-rst, tutorials/distributing-packages.html#register-your-project,
177-
tutorials/distributing-packages.html#requirements-for-packaging-and-distributing,
176+
tutorials/distributing-packages.html#python-requires, tutorials/distributing-packages.html#readme-rst,
177+
tutorials/distributing-packages.html#register-your-project, tutorials/distributing-packages.html#requirements-for-packaging-and-distributing,
178178
tutorials/distributing-packages.html#scheme-choices, tutorials/distributing-packages.html#scripts,
179179
tutorials/distributing-packages.html#semantic-versioning-preferred, tutorials/distributing-packages.html#serial-versioning,
180180
tutorials/distributing-packages.html#setup-args, tutorials/distributing-packages.html#setup-cfg,

source/tutorials/distributing-packages.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ classifiers
274274
Provide a list of classifiers that categorize your project. For a full listing,
275275
see https://pypi.python.org/pypi?%3Aaction=list_classifiers.
276276

277+
Although the list of classifiers is often used to declare what Python versions
278+
a project supports, this information is only used for searching & browsing
279+
projects on PyPI, not for installing projects. To actually restrict what
280+
Python versions a project can be installed on, use the :ref:`python_requires`
281+
argument.
282+
277283

278284
keywords
279285
~~~~~~~~
@@ -314,6 +320,44 @@ specification that is used to install its dependencies.
314320
For more on using "install_requires" see :ref:`install_requires vs Requirements files`.
315321

316322

323+
.. _python_requires:
324+
325+
python_requires
326+
~~~~~~~~~~~~~~~
327+
328+
If your project only runs on certain Python versions, setting the
329+
``python_requires`` argument to the appropriate :pep:`440` version specifier
330+
string will prevent :ref:`pip` from installing the project on other Python
331+
versions. For example, if your package is for Python 3+ only, write::
332+
333+
python_requires='>=3',
334+
335+
If your package is for Python 3.3 and up but you're not willing to commit to
336+
Python 4 support yet, write::
337+
338+
python_requires='~=3.3',
339+
340+
If your package is for Python 2.6, 2.7, and all versions of Python 3 starting
341+
with 3.3, write::
342+
343+
python_requires='>=2.6, !=3.0.*, !=3.1.*, !=3.2.*, <4',
344+
345+
And so on.
346+
347+
.. note::
348+
349+
Support for this feature is relatively recent. Your project's source
350+
distributions and wheels (see :ref:`Packaging Your Project`) must be built
351+
using at least version 24.2.0 of :ref:`setuptools` in order for the
352+
``python_requires`` argument to be recognized and the appropriate metadata
353+
generated.
354+
355+
In addition, only versions 9.0.0 and higher of :ref:`pip` recognize the
356+
``python_requires`` metadata. Users with earlier versions of pip will be
357+
able to download & install projects on any Python version regardless of the
358+
projects' ``python_requires`` values.
359+
360+
317361
.. _`Package Data`:
318362

319363
package_data

0 commit comments

Comments
 (0)