pip-3.3安装MySQL python

2024-05-13 09:21:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有个错误

pip版本

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

如何在Python3.3helpp.中安装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

Tags: pipinfrompyimportinfoeggsetup
3条回答

在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

在python3中,ConfigParser被重命名为configparser。似乎MySQL-python不支持python3。尝试:

$ pip install PyMySQL

PyMySQL是另一个模块,但它支持python3。

pip install --allow-external mysql-connector-python

编辑设置.py

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

相关问题 更多 >