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

什么好主意吗?


当前回答

我在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

其他回答

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

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

请看看/usr/bin/python指向什么

如果指向python3或更高,则更改为python2.7

这应该能解决问题。

我得到的所有python包的安装错误。Abe Karplus的解决方案和讨论给了我关于问题所在的提示。 然后我想起我手动将/usr/bin/python从python2.7更改为/usr/bin/python3.5,这实际上是导致问题的原因。有一次我又变回原来的样子。问题解决了。

在python3上不支持MySQL-python,你可以使用mysqlclient

如果您使用的是fedora/centos/Red Hat,请安装以下软件包

Yum安装python3-devel PIP安装mysqlclient

我运行kali linux- Rolling,当我尝试在终端中运行cup .py时,在更新到python 3.6.0后,我遇到了这个问题。经过一些研究和试验,我发现将ConfigParser更改为ConfigParser对我有用,但随后我遇到了另一个问题。

自信。 吸引:模块“说服器”没有吸引“说服器”

经过更多的研究,我意识到对于python 3, ConfigParser被更改为ConfigParser,但注意它有一个属性ConfigParser()。

下面是@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