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

什么好主意吗?


当前回答

先pip3安装PyMySQL,再pip3安装mysqlclient。 为我工作

其他回答

下面是@MaciejNg,我试着复制了一份,但没有成功:

sudo cp ./env/lib/python3.8/site-packages/configparser.py ./env/lib/python3.8/site-packages/ConfigParser.py

因为configparser.py和configparser.py是相同的,所以我重命名了这个文件:

sudo mv ./env/lib/python3.8/site-packages/configparser.py ./env/lib/python3.8/site-packages/ConfigParser.py

对我来说,下面的命令是有效的:

sudo python3 -m pip install mysql-connector

这对我很有效

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

我仍然有这个问题,所以我去/usr/lib/python3.8,输入sudoer:

cp configparser.py ConfigParser.py

你的python版本可能不是3.8。

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