【问题标题】:pip-3.3 install MySQL-pythonpip-3.3 安装 MySQL-python
【发布时间】:2013-12-01 17:01:57
【问题描述】:

我收到一个错误

pip 版本

pip-3.3 -V 来自 /usr/local/lib/python3.3/site-packages/pip-1.4.1-py3.3.egg (python 3.3) 的 pip 1.4.1

如何在Python3.3帮助中安装MySQLdb..

root@thinkpad:~# pip-3.3 install MySQL-python 
Downloading/unpacking MySQL-python
  Downloading MySQL-python-1.2.4.zip (113kB): 113kB downloaded
  Running setup.py egg_info for package MySQL-python
    Traceback (most recent call last):
      File "<string>", line 16, in <module>
      File "/tmp/pip_build_root/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 "/tmp/pip_build_root/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'

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/MySQL-python
Storing complete log in /root/.pip/pip.log

【问题讨论】:

  • 遗憾的是,MySQL-python 目前不支持 Python 3。您必须要么回滚到 python 2.x,要么使用另一个包。 Source
  • 参见:stackoverflow.com/questions/27748556/…pip install mysqlclient - MySQL-python 叉子)。

标签: python mysql django


【解决方案1】:

在python3中ConfigParser被重命名为configparser。看来MySQL-python 不支持python3。试试:

$ pip install PyMySQL

PyMySQL 是一个不同的模块,但它支持 python3。

【讨论】:

  • django中如何连接pymysqldb?
  • @PyDroid 正如 Piotr Migdal 在他的问题评论中所说。你应该在 Django 中使用 mysqlclient for MySQL for Python3。 docs.djangoproject.com/en/1.8/ref/databases/… Django 使用 MySQL 的推荐选择。
【解决方案2】:

在python3中,通过source安装MySQL-python-1.2.5,在此之前,需要修改源代码:

  • 将文件 MySQL-python-1.2.5/setup_posix.py 文件中的 ConfigParser 替换为 configparser
  • 将 MySQL-python-1.2.5/build/lib.linux-x86_64-3.4/MySQLdb/cursors.py 文件中的第 191 行,except TypeError, m: 修改为 except TypeError as m:
  • 将同一 cursors.py 文件中的第 250 行,except TypeError, msg: 修改为 except TypeError as msg:
  • 修改 MySQL-python-1.2.5/build/lib.linux-x86_64-3.4/MySQLdb/connections.py 文件中的第 36 行,raise errorclass, errorvalueraise errorclass(errorvalue)

要了解更多信息,请参阅Python3 porting guide

【讨论】:

    【解决方案3】:
    pip install --allow-external mysql-connector-python
    

    编辑 settings.py

    'ENGINE': 'mysql.connector.django',
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-21
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-09
      • 2014-07-19
      相关资源
      最近更新 更多