2017-02-13 38 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