我试图pip安装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$ 

什么好主意吗?


当前回答

这对我很有效

cp /usr/local/lib/python3.5/configparser.py /usr/local/lib/python3.5/ConfigParser.py

其他回答

我进一步回答了瓦莱勒的问题:

PIP安装configparser sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/configparser.py 然后尝试重新安装MYSQL-python。这对我很有用

我建议链接这个文件,而不是复制它。这是保存更新。我将文件链接到/usr/lib/python3/目录。

在Python 3中,ConfigParser已重命名为ConfigParser以符合PEP 8。看起来您正在安装的包不支持Python 3。

试试这个对我很有效的方法。

基本上就是从brew重新安装/升级到最新版本的mysql,然后从global pip3而不是virtualenv pip3安装mysqlclient或mysql - python。

然后访问virtualenv并成功安装mysqlclient或MySQL-Python。

先检查一下你使用的Python版本如何?

import six
if six.PY2:
    import ConfigParser as configparser
else:
    import configparser

configparser的Python 2/3兼容性可以简单地通过六个库来解决

from six.moves import configparser