赞
踩
ModuleNotFoundError: No module named ‘django’ 问题1解决
当执行python manage.py migrate报错如下,说没有找到module named ‘django’
Error Reproduce:
mamerunminmatoMacBook-Pro:learning_log RunMin$ source ll_env/bin/activate
(ll_env) mamerunminmatoMacBook-Pro:learning_log RunMin$ python manage.py migrate
Traceback (most recent call last):
File “manage.py”, line 8, in
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named ‘django’
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “manage.py”, line 14, in
) from exc
ImportError: Couldn’t import Django. Are you sure it’s installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Analysis:
但是执行命令pip list是安装了Djgons的,如下:
(ll_env) mamerunminmatoMacBook-Pro:learning_log RunMin$ pip list
Package Version
Django 2.1.5
pip 18.1
pytz 2018.9
setuptools 39.0.1
后来才发现,在Termianl终端默认调用的python解释器是/usr/bin/python,而非当前django创建的虚拟环境下的 python解释器。故使用绝对路径调用python解释器,可以正常执行/Volumes/IMACII/Python/learning_log/ll_env/bin/python manage.py migrate
Solution:
(ll_env) mamerunminmatoMacBook-Pro:learning_log RunMin$ ls
learning_log ll_env manage.py
(ll_env) mamerunminmatoMacBook-Pro:learning_log RunMin$ /Volumes/IMACII/Python/learning_log/ll_env/bin/python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial… OK
Applying auth.0001_initial… OK
Applying admin.0001_initial… OK
Applying admin.0002_logentry_remove_auto_add… OK
Applying admin.0003_logentry_add_action_flag_choices… OK
Applying contenttypes.0002_remove_content_type_name… OK
Applying auth.0002_alter_permission_name_max_length… OK
Applying auth.0003_alter_user_email_max_length… OK
Applying auth.0004_alter_user_username_opts… OK
Applying auth.0005_alter_user_last_login_null… OK
Applying auth.0006_require_contenttypes_0002… OK
Applying auth.0007_alter_validators_add_error_messages… OK
Applying auth.0008_alter_user_username_max_length… OK
Applying auth.0009_alter_user_last_name_max_length… OK
Applying sessions.0001_initial… OK
(ll_env) mamerunminmatoMacBook-Pro:learning_log RunMin$
Summary:
调用python 解释器时, 一定注意当前使用的python是哪个环境下的,你可能一不留神创建了多个虚拟环境下的python环境,每个使用pip install lib_name安装的library不一样,尽量避免混淆。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。