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

什么好主意吗?


当前回答

基于你的操作系统使用python3 如果你不知道configparser.py或configparser.py在哪

安装configparser 查找/ -name "configparser.py" CD /usr/local/lib/python3.6/site-packages(基于您的环境) cp configparser.py configparser.py

解决问题

其他回答

我在Mac OS 10, Python 3.7.6和Django 2.2.7上得到了同样的错误。我想利用这个机会分享在尝试了许多解决方案后对我有效的方法。

步骤

Installed Connector/Python 8.0.20 for Mac OS from link Copy current dependencies into requirements.txt file, deactivated the current virtual env, and deleted it using; create the file if not already created with; touch requirements.txt copy dependency to file; python -m pip3 freeze > requirements.txt deactivate and delete current virtual env; deactivate && rm -rf <virtual-env-name> Created another virtual env and activated it using; python -m venv <virtual-env-name> && source <virtual-env-name>/bin/activate Install previous dependencies using; python -m pip3 install -r requirements.txt

这对我很有效

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

基于你的操作系统使用python3 如果你不知道configparser.py或configparser.py在哪

安装configparser 查找/ -name "configparser.py" CD /usr/local/lib/python3.6/site-packages(基于您的环境) cp configparser.py configparser.py

解决问题

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

sudo python3 -m pip install mysql-connector

额外的信息:

Python 2 x

import ConfigParser

Python 3 x

import configparser