python - 安装 MySQL-python 时出错

标签 python mysql pip

我使用的是 Python 2.7 和 Django 1.9.4。我想将我的 Django 应用程序与 MySQL 5.7 数据库集成,我执行了:

pip install MySQL-python

在 64 位 Windows 7 机器上。

出现错误:

    F:\Djangoproject\mysite>pip install MySQL-python
Collecting MySQL-python
  Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: MySQL-python
  Running setup.py bdist_wheel for MySQL-python ... error
  Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\chandra\\appdata\\local\\temp\\pip-build
-3qbbxo\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__
, 'exec'))" bdist_wheel -d c:\users\chandra\appdata\local\temp\tmpoytuplpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-2.7
  copying _mysql_exceptions.py -> build\lib.win32-2.7
  creating build\lib.win32-2.7\MySQLdb
  copying MySQLdb\__init__.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\converters.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\connections.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\cursors.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\release.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\times.py -> build\lib.win32-2.7\MySQLdb
  creating build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\__init__.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\CR.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\ER.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\FLAG.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\REFRESH.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\CLIENT.py -> build\lib.win32-2.7\MySQLdb\constants
  running build_ext
  building '_mysql' extension
  creating build\temp.win32-2.7
  creating build\temp.win32-2.7\Release
  C:\Users\Chandra\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_info
=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_mys
ql.c /Fobuild\temp.win32-2.7\Release\_mysql.obj /Zl
  _mysql.c
  _mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
  error: command 'C:\\Users\\Chandra\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit statu
s 2

  ----------------------------------------
  Failed building wheel for MySQL-python
  Running setup.py clean for MySQL-python
Failed to build MySQL-python
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python ... error
    Complete output from command c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\chandra\\appdata\\local\\temp\\pip-bui
ld-3qbbxo\\MySQL-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file
__, 'exec'))" install --record c:\users\chandra\appdata\local\temp\pip-rskyc7-record\install-record.txt --single-version-externally-managed --compile:

    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-2.7
    copying _mysql_exceptions.py -> build\lib.win32-2.7
    creating build\lib.win32-2.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-2.7\MySQLdb
    creating build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\REFRESH.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-2.7\MySQLdb\constants
    running build_ext
    building '_mysql' extension
    creating build\temp.win32-2.7
    creating build\temp.win32-2.7\Release
    C:\Users\Chandra\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_in
fo=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python27\include -Ic:\python27\PC /Tc_m
ysql.c /Fobuild\temp.win32-2.7\Release\_mysql.obj /Zl
    _mysql.c
    _mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
    error: command 'C:\\Users\\Chandra\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit sta
tus 2

    ----------------------------------------
Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\chandra\\appdata\\local\\temp\\pip-build-3qbbxo\\MySQL-python\
\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --
record c:\users\chandra\appdata\local\temp\pip-rskyc7-record\install-record.txt --single-version-externally-managed --compile" failed with error code
1 in c:\users\chandra\appdata\local\temp\pip-build-3qbbxo\MySQL-python\

最佳答案

最简单的方法是使用预编译的 python 包,可以在这里找到 http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

关于python - 安装 MySQL-python 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41628482/

相关文章:

python - 在django中读取本地文件

python - 将列表的列表转换为字典,重复值的列表

python - 如何检查 celery 结果后端是否正常工作

python - 正则表达式、多括号和方括号

mysql - 内连接获取所有属性

php - MYSQL 查询结果重复

PHP PDO - INSERT INTO 与 bindParam 不起作用

python - 如何获取已安装的脚本以忽略 PYTHONPATH

python - Pip "install"安装在 Jython 而不是 python 中

python - 使用 python 2.7.9 安装 pip 时出现 HTTPSHandler 错误