ModuleNotFoundError: No module named 'MySQLdb'


现象

出现:ModuleNotFoundError: No module named 'MySQLdb'

(venv) D:\pycharm\Django_01\myapp>python manage.py runserver 0.0.0.0:8800
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "D:\pycharm\Django_01\venv\lib\site-packages\django\db\backends\mysql\base.py", line 16, in <module>
    import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'

The above exception was the direct cause of the following exception:

背景

更换django项目的默认数据库为mysql,然后使用命令行(python manage.py runserver 0.0.0.0:8800)再启动,报错

解决方案

1、使用命令行安装mysql的客户端

pip install mysqlclient

2、安装whl, whl包的下载路径

pip install mysqlclient-1.4.6-cp37-cp37m-win_amd64.whl

再次启动,则是ok

(venv) D:\pycharm\Django_01\myapp>python manage.py runserver 0.0.0.0:8800
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
March 22, 2022 - 19:01:41
Django version 3.0, using settings 'myapp.settings'
Starting development server at http://0.0.0.0:8800/
Quit the server with CTRL-BREAK.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM