加载 MySQLdb 模块时出错“您安装了 mysqlclient 还是 MySQL-python?"

Error loading MySQLdb Module #39;Did you install mysqlclient or MySQL-python?#39;(加载 MySQLdb 模块时出错“您安装了 mysqlclient 还是 MySQL-python?)

本文介绍了加载 MySQLdb 模块时出错“您安装了 mysqlclient 还是 MySQL-python?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 python34 的 django 项目中使用 windows 10 命令行,但是,我在使用 SQL 时遇到了困难.

I am using windows 10 command line for a django project using python34 however, I am facing difficulties with SQL.

我已经使用 pip install mysqlclient==1.3.5 安装了 mysqlclient 并找到了该文件以确保我没有错觉.然后我运行 python manage.py migrate 将表迁移到 SQL 数据库(我使用的是 phpmyadmin).但是,当命令返回...

I have already installed mysqlclient using pip install mysqlclient==1.3.5 and located the file to make sure I was not delusional. I then ran python manage.py migrate to migrate the tables to the SQL database (I am using phpmyadmin). However when the command returned with...

 File "C:Usersuserenvlibsite-packagesdjangodbackendsmysqlase.py", line 30, in <module>
    'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?

我知道这样的问题已经存在,但似乎没有一种解决方案对尝试产生任何影响.提前致谢.

I am aware that questions like these already exist, but not one solution seems to have made any impact on attempts. Thank you in advance.

推荐答案

pip install pymysql

然后,在你的项目源目录中编辑__init__.py文件(与settings.py相同)

Then, edit the __init__.py file in your project origin dir(the same as settings.py)

添加:

import pymysql

pymysql.install_as_MySQLdb()

这篇关于加载 MySQLdb 模块时出错“您安装了 mysqlclient 还是 MySQL-python?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:加载 MySQLdb 模块时出错“您安装了 mysqlclient 还是 MySQL-python?"

基础教程推荐