Python 3 ImportError:没有名为“ ConfigParser”的模块

本文翻译自: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 higherpython3 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/pythonpython2.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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值