在 ubuntu 上安装 MySQLDb 时出错

在 ubuntu 上安装 MySQLDb 时出错

我正在使用 python3

我正在尝试安装 MySQLdb,

$ pip3  install mysql-python
Collecting mysql-python
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-g34d6t3j/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/tmp/pip-build-g34d6t3j/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'

所以我尝试安装 ConfigParser 并发现 ConfigParser 在 python3 中被重命名为 configParser,现在我安装configparser在 上python3

~$ pip3 install configParser
Collecting configParser
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/7a/2a/95ed0501cf5d8709490b1d3a3f9b5cf340da6c433f896bbe9ce08dbe6785/configparser-4.0.2-py2.py3-none-any.whl
Installing collected packages: configParser
Successfully installed configParser-4.0.2

但我仍然收到错误说:

~$ pip3  install mysql-python
Collecting mysql-python
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-qkip1b53/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/tmp/pip-build-qkip1b53/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-qkip1b53/mysql-python/

任何帮助将不胜感激。

答案1

mysql-python与 Python3 不兼容,无法使用 安装pip3

使用mysql客户端(Ubuntu 中的软件包python3-mysqldb)或查看Python 维基了解从 Python 访问 MySQL 的更多可能性。

相关内容