According to Django 2.0 release notes Django 2.0 onwards will only support python 3, making the 1.11.X the last release series to support python 2.
See quote from the release notes page:
Django 2.0 supports Python 3.4, 3.5, and 3.6. We highly recommend and only officially support the latest release of each series.
The Django 1.11.x series is the last to support Python 2.7.
However when running pip2 install Django
, django version 2 is being installed (which then fails because it assumes functionality not available in python 2):
(venv-crap) mbp15:server nir$ pip2 install django
Collecting django
Downloading Django-2.0.tar.gz (8.0MB)
100% |████████████████████████████████| 8.0MB 177kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/PATH/django/setup.py", line 32, in <module>
version = __import__('django').get_version()
File "django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "django/utils/version.py", line 61, in <module>
@functools.lru_cache()
AttributeError: 'module' object has no attribute 'lru_cache'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/PATH/django/
I know I can manually specify requirement version below 2, making pip install a version valid for python 2, however that will complicate the installation process if I want to support both python2 and python3, and would have assumed pip will know to install only versions compatible with the python it's running from.
My questions, therefore, as the following:
- Why is pip attempting to install Django2 with python2 instead of automatically picking the last compatible version? Isn't that part of
pip
s capabilities? - Is there a way to make a single
requirements.txt
that will installDjango<2.0
when running from python2 andDjango>=2.0
when running with python3?
As Alasdair pointed out in the comments already, this is a known bug in Django: bug #28878.
You can use the environment markers (see PEP 508):
This will install one and skip another django dependency, depending on what python you are using: