When you try to install Django, you may encounter this error message:
AttributeError: 'module' object has no attribute 'lru_cache' ... Command "python setup.py egg_info" failed with error code 1
The cause of this error is most likely that you are trying to install Django 2.0 using an unsupported version of Python, e.g. Python 2.7.
To solve this problem you can either use Python 3.4 or newer or install a version of Django that is compatible with your version of Python. If you are using Python 2.7, this would be Django 1.11, at the time of writing 1.11.9.
You can install Django 1.11 with
pip like this:
pip install "Django==1.11.*"
Note that we specified
1.11. This ensures that we get the latest patch release version of Django 1.11 containing bugfixes and security patches.
Alternatively, you could also install it like this:
pip install "Django<2"
For reference, here is the error message in all its glory:
$ pip install django Collecting django Using cached Django-2.0.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/p3/3ty8s03j475b3578qr1qmplc0000gn/T/pip-build-kClHpD/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/var/folders/p3/3ty8s03j475b3578qr1qmplc0000gn/T/pip-build-kClHpD/django/
This issue has been fixed in Django 2.0.1 by adding the
python_requires directive to setup.py. It ensures that
pip won’t even try to install versions of Django that incompatible with your current version of Python.
Unfortunately, this fix cannot be applied to Django 2.0 retroactively, so we are stuck with this error message until the last Django user has migrated away from Python 2.7.