Python ModuleNotFoundError:没有名为';django';使用mkproject创建项目时

Python ModuleNotFoundError:没有名为';django';使用mkproject创建项目时,python,django,virtualenvwrapper,Python,Django,Virtualenvwrapper,我正在尝试使用VirtualNVRapper创建一个django项目。我已经安装了virtualenvwrapper和virtualenvwrapper.django模板。但是,每当我尝试使用mkproject命令创建django项目时,就会出现标题中提到的错误。这是我的终端输出: $ mkproject -t django todolist Using base prefix '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework

我正在尝试使用VirtualNVRapper创建一个django项目。我已经安装了
virtualenvwrapper
virtualenvwrapper.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'
如您所见,Django已安装。此外,当我尝试在该环境下手动创建django项目时,也会收到相同的消息:

(todolist) ➜  todolist pip list
Package    Version
---------- -------
Django     2.1.7
pip        19.0.3
pytz       2018.9
setuptools 40.8.0
wheel      0.33.1
(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'
(todolist)➜  django代码django admin startproject mysite
回溯(最近一次呼叫最后一次):
文件“/Users/tanmay/.virtualenvs/todolist/bin/django admin”,第6行,在
从django.core.management导入从命令行执行
ModuleNotFoundError:没有名为“django”的模块

我做错了什么?

head-1/Users/tanmay/.virtualenvs/todolist/bin/django admin
?@phd
#/usr/local/bin/python3
这就是问题所在-它一定是
#/Users/tanmay/.virtualenvs/todolist/bin/python
。指向全局
python
,全局
python
没有安装
django
,因此出现错误
django admin
必须使用virtualenv中的
python
运行。您是正确的。全局python没有django。现在,为了让VirtualEnvrapper从当前虚拟环境而不是全局python获取python路径,应该做些什么?使用适当的解释器运行
django admin
。您可以手动执行此操作:
/Users/tanmay/.virtualenvs/todolist/bin/python/Users/tanmay/.virtualenvs/todolist/bin/django admin
。或者修复shebang行-编辑文件
django admin
,并将第一行替换为
#/Users/tanmay/.virtualenvs/todolist/bin/python
。理论上,这必须在pip安装时自动完成;我不知道为什么
pip
没有自己修复它。
head-1/Users/tanmay/.virtualenvs/todolist/bin/django-admin
?@phd
#/usr/local/bin/python3
这就是问题所在-它一定是
#/Users/tanmay/.virtualenvs/todolist/bin/python
。指向全局
python
,全局
python
没有安装
django
,因此出现错误
django admin
必须使用virtualenv中的
python
运行。您是正确的。全局python没有django。现在,为了让VirtualEnvrapper从当前虚拟环境而不是全局python获取python路径,应该做些什么?使用适当的解释器运行
django admin
。您可以手动执行此操作:
/Users/tanmay/.virtualenvs/todolist/bin/python/Users/tanmay/.virtualenvs/todolist/bin/django admin
。或者修复shebang行-编辑文件
django admin
,并将第一行替换为
#/Users/tanmay/.virtualenvs/todolist/bin/python
。理论上,这必须在pip安装时自动完成;我不知道为什么
pip
没有自己修复它。