查看: 2133|回复: 4

AttributeError: 'module' object has no attribute 'lru_cache'

[复制链接]

15

主题

97

帖子

310

积分

论坛管理

Rank: 4

积分
310
发表于 2018-9-27 15:48:08 | 显示全部楼层 |阅读模式
我通过以下方式安装django:
git clone git://github.com/django/django.git
pip install -e django/
I use Ubuntu 16.04.
发生了以下错误
Obtaining file:///home/leo/django
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/home/leo/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 60, in <module>
        @functools.lru_cache()
    AttributeError: 'module' object has no attribute 'lru_cache'
怎么修复这个错误?
回复

使用道具 举报

5

主题

41

帖子

108

积分

注册会员

Rank: 2

积分
108
发表于 2018-9-27 15:49:40 | 显示全部楼层
上一个Django版本不支持python 2.7。如果您真的想要使用python 2.7和Django,您应该安装以前的Django版本。最新支持的是:1.11,因此,只需运行:pip install django==1.11
回复

使用道具 举报

13

主题

53

帖子

131

积分

注册会员

Rank: 2

积分
131
发表于 2018-9-27 15:51:57 | 显示全部楼层
这是因为django版本需要python3解释器。因此,尝试使用pip3运行相同的命令
sudo apt-get -y install python3-pip
install pip3 sudo apt-get -y install python3-pip
回复

使用道具 举报

10

主题

82

帖子

200

积分

中级会员

Rank: 3Rank: 3

积分
200
发表于 2018-9-27 15:53:19 | 显示全部楼层
可以使用git安装Python 2版本的Django
git clone git://github.com/django/django.git
cd django
git checkout 1.11.0
cd ..
pip install -e django/
回复

使用道具 举报

11

主题

63

帖子

159

积分

注册会员

Rank: 2

积分
159
发表于 2018-9-27 15:54:29 | 显示全部楼层
Right > c:\Python27\Scripts>pip install django==1.11
Wrong > c:\Python27\Scripts>pip2.7 install django

c:\Python27\Scripts>pip2.7 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 "c:\users\shyv\appdata\local\temp\pip-build-idpp6j\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 c:\users\shyv\appdata\local\temp\pip-build-idpp6j\django\

c:\Python27\Scripts>pip install django==1.11
Collecting django==1.11
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cau
  SNIMissingWarning
c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL co
  InsecurePlatformWarning
  Downloading Django-1.11-py2.py3-none-any.whl (6.9MB)
    100% |################################| 6.9MB 108kB/s
Collecting pytz (from django==1.11)
  Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
    100% |################################| 512kB 922kB/s
Installing collected packages: pytz, django
Successfully installed django-1.11 pytz-2017.3
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表