标题在虚拟环境中django 2.0.2 已安装,进入python后import django错
ModuleNotFoundError: No module named 'django’
$ workon rangoenv
(rangoenv
) ~$ python --version
Python 3.8.5
(rangoenv
) $ python
Python 3.8.5
(v3.8.5:580fbb018f, Jul 20 2020, 12:11:27
)
[Clang 6.0
(clang-600.0.57
)] on darwin
Type
"help",
"copyright",
"credits" or
"license" for more information.
>>> import django
Traceback
(most recent call last
):
File
"<stdin>", line 1,
in <module
>
ModuleNotFoundError: No module named
'django'
查错原因:
Django 版本同python版本不对应
解决方案:
在terminal 中使用pip3 install django 安装最新版本Django使用pip3 freeze 获取 Django最新版本号 Django==3.1.2回到虚拟环境中,使用$ pip install Django==3.1.2 安装相应 Django
$ python
Python 3.8.5
(v3.8.5:580fbb018f, Jul 20 2020, 12:11:27
)
[Clang 6.0
(clang-600.0.57
)] on darwin
Type
"help",
"copyright",
"credits" or
"license" for more information.
>>> import django
>>> django.get_version
()
'3.1.2'