Python django報錯ImportError: cannot import name find_spec

EpisodeOne發表於2016-05-17

執行 django-admin startproject mysite報錯如下:

<span style="font-size:14px;">[root@host django]# django-admin startproject mysite
Traceback (most recent call last):
  File "/usr/local/bin/django-admin", line 9, in <module>
    load_entry_point('Django==1.9.6', 'console_scripts', 'django-admin')()
  File "/usr/local/lib/python3.3/site-packages/setuptools-2.0-py3.3.egg/pkg_resources.py", line 348, in load_entry_point
  File "/usr/local/lib/python3.3/site-packages/setuptools-2.0-py3.3.egg/pkg_resources.py", line 2311, in load_entry_point
  File "/usr/local/lib/python3.3/site-packages/setuptools-2.0-py3.3.egg/pkg_resources.py", line 2025, in load
  File "/usr/local/lib/python3.3/site-packages/Django-1.9.6-py3.3.egg/django/core/management/__init__.py", line 10, in <module>
    from django.apps import apps
  File "/usr/local/lib/python3.3/site-packages/Django-1.9.6-py3.3.egg/django/apps/__init__.py", line 1, in <module>
    from .config import AppConfig
  File "/usr/local/lib/python3.3/site-packages/Django-1.9.6-py3.3.egg/django/apps/config.py", line 6, in <module>
    from django.utils.module_loading import module_has_submodule
  File "/usr/local/lib/python3.3/site-packages/Django-1.9.6-py3.3.egg/django/utils/module_loading.py", line 67, in <module>
    <span style="color:#ff0000;">from importlib.util import find_spec as importlib_find</span></span>

搜尋以後發現是python版本不正確,我的執行環境是Python3.3.0

find_spec isn't available in Python 3.2.3; it was added in Python 3.4.
於是重新安裝Python3.4.0或者升級

  wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0.tgz 

  tar -zxvf Python-3.4.0.tgz 
  cd Python-3.4.0
  ./configure 
  make all
  make install
  make clean
  make distclean
  /usr/local/bin/python3 -v

再次執行命令

#django-admin startproject mysite

於是就建立了mysite檔案

相關文章