Python 3 ImportError:没有名为“ConfigParser”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14087598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 3 ImportError: No module named 'ConfigParser'
提问by if __name__ is None
I am trying to pip installthe MySQL-pythonpackage, 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?
有任何想法吗?
采纳答案by Abe Karplus
In Python 3, ConfigParserhas been renamed to configparserfor PEP 8 compliance. It looks like the package you are installing does not support Python 3.
在 Python 3 中,ConfigParser已重命名configparser为 PEP 8 合规性。您正在安装的软件包似乎不支持 Python 3。
回答by Eldamir
You can instead use the mysqlclientpackage as a drop-in replacement for MySQL-python. It is a fork of MySQL-pythonwith added support for Python 3.
您可以改为使用该mysqlclient包作为 MySQL-python 的替代品。它是一个 fork,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 的,但我只是想分享我的成功:)
回答by sorin
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 sixmodule, 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
回答by Fooo
Kindly to see what is /usr/bin/pythonpointing to
请看看/usr/bin/python指的是什么
if it is pointing to python3 or higherchange to python2.7
如果它指向python3 or higher更改为python2.7
This should solve the issue.
这应该可以解决问题。
I was getting install error for all the python packages. Abe Karplus's solution & discussion gave me the hint as to what could be the problem.
Then I recalled that I had manually changed the /usr/bin/pythonfrom python2.7to /usr/bin/python3.5, which actually was causing the issue. Once I revertedthe same. It got solved.
我收到所有 python 包的安装错误。Abe Karplus 的解决方案和讨论给了我可能是什么问题的提示。然后我回忆起我手动将/usr/bin/pythonfrom更改python2.7为/usr/bin/python3.5,这实际上是导致问题的原因。一旦我reverted一样。它得到了解决。
回答by MaciejNg
This worked for me
这对我有用
cp /usr/local/lib/python3.5/configparser.py /usr/local/lib/python3.5/ConfigParser.py
回答by Gaurav Nagpal
If you are using CentOS, then you need to use
如果您使用的是 CentOS,那么您需要使用
yum install python34-devel.x86_64yum groupinstall -y 'development tools'pip3 install mysql-connectorpip install mysqlclient
yum install python34-devel.x86_64yum groupinstall -y 'development tools'pip3 install mysql-connectorpip install mysqlclient
回答by Kaushal
MySQL-python is not supported on python3 instead of this you can use mysqlclient
python3 不支持 MySQL-python 而不是你可以使用mysqlclient
If you are on fedora/centos/Red Hatinstall following package
如果您正在fedora/centos/Red Hat安装以下软件包
yum install python3-develpip install mysqlclient
yum install python3-develpip install mysqlclient
回答by Gideon Kimutai
how about checking the version of Python you are using first.
首先检查您使用的Python版本如何。
import six
if six.PY2:
import ConfigParser as configparser
else:
import configparser
回答by Oliver Wahome
I run kali linux- Rolling and I came across this problem ,when I tried running cupp.py in the terminal, after updating to python 3.6.0. After some research and trial I found that changing ConfigParserto configparserworked for me but then I came across another issue.
我运行 kali linux-Rolling 并且在更新到 python 3.6.0 后尝试在终端中运行 cupp.py 时遇到了这个问题。一些研究和试验后,我发现,改变 ConfigParser对 configparser我的工作,但那时,我发现另一个问题就来了。
config = configparser.configparser()
AttributeError: module 'configparser' has no attribute 'configparser'
config = configparser.configparser()
AttributeError: module 'configparser' has no attribute 'configparser'
After a bit more research I realised that for python 3 ConfigParseris changed to configparserbut note that it has an attribute ConfigParser().
经过更多的研究,我意识到对于 python 3 ConfigParser已更改为 configparser但请注意它有一个属性 ConfigParser().
回答by Akif
Compatibility of Python 2/3 for configparsercan be solved simply by sixlibrary
Python 2/3 for 的兼容性configparser可以通过six库简单解决
from six.moves import configparser

