问题
I'm learning Python in tandem with Django. I initially installed Python 3 on my machine (Debian Wheezy), but read about possible conflicts and removed it with some difficulty.
Now I'm using virtualenv and installed python3 within the env and Django using pip. Django and Python seem to have installed correctly:
# python -c "import django; print(django.get_version())"
1.9.1
# python -V
Python 3.2.3`
but when I try to start a new Django project, I get the following:
# django-admin.py startproject mysite
Traceback (most recent call last):
File "/home/rialaado/Projects/webenv/bin/django-admin.py", line 2, in <module>
from django.core import management
File "/home/rialaado/Projects/webenv/lib/python3.2/site-packages/django/core/management/__init__.py", line 10, in <module>
from django.apps import apps
File "/home/rialaado/Projects/webenv/lib/python3.2/site-packages/django/apps/__init__.py", line 1, in <module>
from .config import AppConfig
File "/home/rialaado/Projects/webenv/lib/python3.2/site-packages/django/apps/config.py", line 6, in <module>
from django.utils.module_loading import module_has_submodule
File "/home/rialaado/Projects/webenv/lib/python3.2/site-packages/django/utils/module_loading.py", line 67, in <module>
from importlib.util import find_spec as importlib_find
ImportError: cannot import name find_spec
A quick google turned up no results that would help me.
What should I do?
回答1:
find_spec
isn't available in Python 3.2.3; it was added in Python 3.4.
Try upgrading to 3.4 or later.
回答2:
The version of Django you're using (v1.9.1) cannot be used with Python 3.2. Hence, @KarthiG and @MUNGAI NJOROGE are correct, and now you know why.
What Python version can I use with Django?
回答3:
I got the same problem with docker containers.
find_spec is not available when using Docker containers and django 1.9 and python:3.3 dependency.
Adding the line below in your docker image as a dependency works.
FROM python:3.4
来源:https://stackoverflow.com/questions/34623105/why-do-i-get-importerror-cannot-import-name-find-spec-when-i-start-a-new-djan