系统: CentOS-6.4-x86_64
Python : Python 3.4.5 和 Python 3.5.2
安装 MySQL-python ,结果出错:
ImportError: No module named 'ConfigParser'
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ry1be27_/mysql-python/
原因:
在 Python 3.x 版本后,ConfigParser.py 已经更名为 configparser.py 所以出错!
可以看看系统中的 python 命令 ,系统自带个 python 2.6。
[plain] view plain copy
- [root@centos]# ls /usr/bin/python*
- /usr/bin/python /usr/bin/python2 /usr/bin/python2.6
- [root@centos]#
- [root@centos]# python2.6 -V
- Python 2.6.6
- [root@centos]#
解决方法:两个
一 找到文件 configparser ,更名为旧版本的名称 ConfigParser
cp /usr/local/Python34/lib/python3.4/configparser.py /usr/local/Python34/lib/python3.4/ConfigParser.py
二 import as 改名
try:
import pymysql
except:
pass
try:
import MySQLdb as pymysql
except:
pass
try:
from ConfigParser import ConfigParser
except:
pass
try:
from configparser import ConfigParser
except:
pass
文章出处:http://www.cnblogs.com/aaron-agu/ 只有毅力和决心才能使人真正具有价值!

在CentOS 6.4环境下,尝试安装MySQL-python时遇到ImportError,原因是Python3.x中ConfigParser模块已被重命名为configparser。解决方案包括复制configparser.py为ConfigParser.py或使用import as进行模块名更改。此问题涉及到Python版本兼容性和模块导入。

3129

被折叠的 条评论
为什么被折叠?



