发布于 2年前

解决pip安装django错误:AttributeError: 'module' object has no attribute 'lru_cache'

使用pip安装django2:

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 "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'

原因

这是因为django2.0与Python 2.x不兼容。

lru_cache为Python3.2新增的,而django2.0只支持Python3.4+。

解决方法

对于不兼容问题,解决方法两个:

1、安装django2.0以下的版本,如django 1.11

pip install 'django<2.0'

2、升级到Python3.4以上,但需要注意:Python3和Pytyon2.7是不兼容的。

©2020 edoou.com   京ICP备16001874号-3