本文翻译自:Python 3 ImportError: No module named 'ConfigParser'
I am trying to pip install the MySQL-python package, but I get an ImportError . 我正在尝试pip install MySQL-python软件包,但出现ImportError 。
Jans-MacBook-Pro:~ jan$ /Library/Frameworks/Python.framework/Versions/3.3/bin/pip-3.3 install MySQL-python
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python
Storing complete log in /Users/jan/.pip/pip.log
Jans-MacBook-Pro:~ jan$
Any ideas? 有任何想法吗?
#1楼
参考:https://stackoom.com/question/X6Pk/Python-ImportError-没有名为-ConfigParser-的模块
#2楼
In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance. 在Python 3中, ConfigParser符合PEP 8, ConfigParser已重命名为configparser 。 It looks like the package you are installing does not support Python 3. 您正在安装的软件包似乎不支持Python 3。
#3楼
You can instead use the mysqlclient package as a drop-in replacement for MySQL-python. 您可以改为使用mysqlclient软件包作为MySQL-python的直接替代品。 It is a fork of MySQL-python with added support for Python 3. 它是MySQL-python的分支,增加了对Python 3的支持。
I had luck with simply 我很幸运
pip install mysqlclient
in my python3.4 virtualenv after 在我的python3.4 virtualenv之后
sudo apt-get install python3-dev libmysqlclient-dev
which is obviously specific to ubuntu/debian, but I just wanted to share my success :) 这显然是特定于ubuntu / debian的,但我只是想分享我的成功:)
#4楼
Here is a code that should work in both Python 2.x and 3.x 这是一个在Python 2.x和3.x中均应适用的代码
Obviously you will need the six module, but it's almost impossible to write modules that work in both versions without six. 显然,您将需要six模块,但是编写没有六个版本就可以在两个版本中工作的模块几乎是不可能的。
try:
import configparser
except:
from six.moves import configparser
#5楼
Kindly to see what is /usr/bin/python pointing to 请看看/usr/bin/python指向什么
if it is pointing to python3 or higher change to python2.7 如果它指向python3 or higher , python3 or higher改为python2.7
This should solve the issue. 这应该可以解决问题。
I was getting install error for all the python packages. 我收到所有python软件包的安装错误。 Abe Karplus's solution & discussion gave me the hint as to what could be the problem. 安倍·卡普拉斯(Abe Karplus)的解决方案和讨论给了我有关可能是什么问题的提示。 Then I recalled that I had manually changed the /usr/bin/python from python2.7 to /usr/bin/python3.5 , which actually was causing the issue. 然后我回想起我已经将/usr/bin/python从python2.7手动更改为/usr/bin/python3.5 ,这实际上是导致问题的原因。 Once I reverted the same. 一旦我reverted原样。 It got solved. 解决了
#6楼
这对我有用
cp /usr/local/lib/python3.5/configparser.py /usr/local/lib/python3.5/ConfigParser.py
本文解决在Python3环境下安装MySQL-python包时遇到的ImportError问题,涉及ConfigParser模块名称变更及替代方案mysqlclient包的使用。
757

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



