2017-02-13 62 views
16

我安装Django通过:当我通过git安装django时出现错误?

混帐混帐克隆://github.com/django/django.git

PIP安装-e的Django/

我使用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' 

    ---------------------------------------- 
Command "python setup.py egg_info" failed with error code 1 in /home/leo/django/ 

如何解决这一问题? 谢谢。

+1

你为什么从混帐安装它,而不是用'PIP安装django'?似乎你正试图在Python 2上安装它,而Django的最新开发版本需要Python 3. – kichik

+0

是的,“pip install django”可以解决我的问题。但我只是不知道为什么会发生这个问题? – yensheng

+4

因为你试图在Python 2上安装它,但最新版本的Django需要Python 3. – kichik

回答

16

这是因为你有django版本需要python3解释器。所以尽量使用运行pip3

同一命令来安装pip3 sudo apt-get -y install python3-pip

然后运行

pip3 install -e django/

+13

Django 2.0于2017年12月发布。对于使用python 2.7的用户,您可以通过“pip install django == 1.11.8”安装旧版本的Django。请访问https://www.djangoproject.com/download/以检查最新的发行版本号。 – TimSC

38

最后的Django版本不支持Python 2.7版。

如果你真的想使用python 2.7并且也使用Django,你应该安装一个以前的Django版本。

支持最新的是:1.11

因此,只需要运行:

pip install django==1.11 
+0

这不是一个真正的答案,它是所有这些有点错误! OP需要一种方法来安装Django 2不是旧版本 –

+1

亚历克斯谁告诉你,他想安装Django 2?我怀疑你的论点。 – george

+1

我的名字也是亚历克斯,我对其他亚历克斯的爆发感到羞耻。你的回答帮了我,谢谢。我需要Python 2,因为我依赖于一些专门的软件包。 – a20

-2
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