ModuleNotFoundError: No module named 'django' 问题1解决

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不一样,尽量避免混淆。

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
ModuleNotFoundError: No module named 'django'错误是因为在pycharm中没有找到django模块。这可能是由于以下几个原因造成的: 1. 没有安装django模块。您可以通过在终端中运行以下命令来安装django模块:`pip install django`。 2. 您是否在正确的Python环境中安装了django模块?请确保您在使用pycharm时使用的是正确的Python环境。您可以通过在pycharm中的设置中检查Python解释器来确认。 3. 如果您使用的是Python 3.x版本,那么您需要安装django的兼容版本。MySQL-python不支持Python 3.x,您可以尝试安装mysqlclient模块来解决这个问题。您可以通过在终端中运行以下命令来安装mysqlclient模块:`pip install mysqlclient`。 4. 可能是环境配置问题。请确保您的pycharm环境配置正确,并且可以正确加载django模块。您可以参考引用提供的链接来解决pycharm无法使用conda环境的问题,以确保您的环境正确配置。 综上所述,要解决ModuleNotFoundError: No module named 'django'错误,您需要确保已安装django模块,正确配置Python环境,并尝试安装兼容Python 3.x的mysqlclient模块。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [ModuleNotFoundError: No module nameddjango](https://blog.csdn.net/weixin_46322789/article/details/127431140)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Django重装mysql后启动报错:No module named ‘MySQLdb’的解决方法](https://download.csdn.net/download/weixin_38722052/13987704)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值