ModuleNotFoundError:使用mkproj创建项目时没有名为“Django”的模块

2024-04-16 13:20:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用virtualenvwrapper创建一个django项目。我已经安装了virtualenvwrappervirtualenvwrapper.django模板。但是每当我试图使用mkproject命令创建django项目时,我会得到标题中提到的错误。这是我的终端输出:

$ mkproject -t django todolist
Using base prefix '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7'
New python executable in /Users/tanmay/.virtualenvs/todolist/bin/python3.7
Not overwriting existing python script /Users/tanmay/.virtualenvs/todolist/bin/python (you must use /Users/tanmay/.virtualenvs/todolist/bin/python3.7)
Installing setuptools, pip, wheel...
done.
virtualenvwrapper_cd:cd:6: no such file or directory: /Users/tanmay/django-code/todolist
Creating /Users/tanmay/django-code/todolist
Setting project for todolist to /Users/tanmay/django-code/todolist

Applying template  django
Requirement already satisfied: django in /Users/tanmay/.virtualenvs/todolist/lib/python3.7/site-packages (2.1.7)
Requirement already satisfied: pytz in /Users/tanmay/.virtualenvs/todolist/lib/python3.7/site-packages (from django) (2018.9)
virtualenvwrapper.django Running "django-admin.py startproject todolist"
Traceback (most recent call last):
  File "/Users/tanmay/.virtualenvs/todolist/bin/django-admin.py", line 2, in <module>
    from django.core import management
ModuleNotFoundError: No module named 'django'
(todolist) ➜  todolist python
Python 3.7.0 (default, Oct  2 2018, 09:18:58)
[Clang 10.0.0 (clang-1000.11.45.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from django import get_version
>>> get_version()
'2.1.7'

还有该环境中的pip包列表:

^{pr2}$

如您所见,Django已安装。此外,当我尝试在该环境下手动创建django项目时,也会收到相同的消息:

(todolist) ➜  django-code django-admin startproject mysite
Traceback (most recent call last):
  File "/Users/tanmay/.virtualenvs/todolist/bin/django-admin", line 6, in <module>
    from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'

我做错什么了?在


Tags: 项目djangoinfromimportbinadminline