Error loading MySQLdb module: No module named MySQLdb 错误的解决方法

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介:

具体报错如下:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb


解法办法:

需要安装python连接mysql的模块

注意:本人使用yum install MySQL-pyton安装后依然报上错误,经测试必须要pip方式安装

pip install mysql-python


如果安装报以下错误:

pip install pandas` gives UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 41: ordinal not in range(128)


则需要升级pip版本:

pip install --upgrade pip


升级完成后重装安装mysql-python

pip install mysql-python


如果安装报以下错误:

_mysql.c:2091: error: ‘r’ undeclared (first use in this function)

_mysql.c:2091: error: ‘_mysql_ResultObject’ has no member named ‘result’

_mysql.c:2092: error: ‘_mysql_ResultObject’ has no member named ‘result’

_mysql.c: In function ‘_mysql_ResultObject_dealloc’:

_mysql.c:2100: warning: implicit declaration of function ‘mysql_free_result’

_mysql.c:2100: error: ‘_mysql_ResultObject’ has no member named ‘result’

_mysql.c: At top level:

_mysql.c:2331: error: ‘_mysql_ConnectionObject’ has no member named ‘open’

_mysql.c:2338: error: ‘_mysql_ConnectionObject’ has no member named ‘converter’

_mysql.c:2345: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’

_mysql.c:2352: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’

_mysql.c:2359: error: ‘_mysql_ConnectionObject’ has no member named ‘connection’

_mysql.c:2422: error: ‘_mysql_ResultObject’ has no member named ‘converter’

_mysql.c:2422: error: initializer element is not constant

_mysql.c:2422: error: (near initialization for ‘_mysql_ResultObject_memberlist[0].offset’)

_mysql.c: In function ‘_mysql_ConnectionObject_getattr’:

_mysql.c:2444: error: ‘_mysql_ConnectionObject’ has no member named ‘open’

error: command 'gcc' failed with exit status 1


解决方法:yum -y install mysql-devel libxml2 libxml2-dev libxslt* zlib gcc openssl


安装完成后再次尝试安装mysql-python

pip install mysql-python

[xxxx@test1 Craxsxx]# pip install mysql-python

Collecting mysql-python

  Using cached MySQL-python-1.2.5.zip

Installing collected packages: mysql-python

  Running setup.py install for mysql-python

Successfully installed mysql-python-1.2.5


mysql-python的模块安装成功




本文转自 jvrmusic520  51CTO博客,原文链接:http://blog.51cto.com/linuxtech/1732301
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
pip安装skbuild报错:ModuleNotFoundError: No module named ‘skbuild’解决方法
pip安装skbuild报错:ModuleNotFoundError: No module named ‘skbuild’解决方法,换源
747 0
|
TensorFlow 算法框架/工具 计算机视觉
No module named ‘cv2‘ 解决办法 (No module named ‘numpy‘ 等所有报错均可解决)
No module named ‘cv2‘ 解决办法 (No module named ‘numpy‘ 等所有报错均可解决)
|
Linux
原因及解决办法:Failed to load module “canberra-gtk-module“
原因及解决办法:Failed to load module “canberra-gtk-module“
887 0
|
Python
解决办法:ImportError: No module named pycuda.driver
解决办法:ImportError: No module named pycuda.driver
294 0
|
NoSQL Python
解决gdb报错:Failed to import the site module,No module named '_sysconfigdata_m'
解决gdb报错:Failed to import the site module,No module named '_sysconfigdata_m'
393 0
ImportError: No module named _internal
ImportError: No module named _internal
100 0
成功解决Module Not Found Error : No module named mglearn
成功解决Module Not Found Error : No module named mglearn
|
关系型数据库 Python MySQL