首页 > 解决方案 > 为什么 pip install MySQL-python==1.2.5 因 C 编译错误而失败?

问题描述

我在运行 MacOS High Sierra(版本 10.13.4)的 Macbook 上运行虚拟环境。

在虚拟环境中,我正在执行 pip install MySQL-python。但它失败并出现如下所示的 C 编译错误。

此错误的原因是什么,我该如何解决?

$ pip install MySQL-python==1.2.5
Collecting MySQL-python==1.2.5
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/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 /Users/saqib.ali/saqib_bnet_docs/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/q7/zl0gz8xj7ps8wswmxkqsf9khwzyc1z/T/pip-install-KM5pDI/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 /private/var/folders/q7/zl0gz8xj7ps8wswmxkqsf9khwzyc1z/T/pip-wheel-qP6Us6 --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.13-intel-2.7
  copying _mysql_exceptions.py -> build/lib.macosx-10.13-intel-2.7
  creating build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  creating build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.macosx-10.13-intel-2.7
  cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -I/usr/local/opt/openssl/include -arch i386 -arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mariadb/10.3.10/include/mysql -I/usr/local/Cellar/mariadb/10.3.10/include/mysql/.. -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.13-intel-2.7/_mysql.o
  In file included from _mysql.c:44:
  /usr/local/Cellar/mariadb/10.3.10/include/mysql/my_config.h:3:2: warning: This file should not be included by clients, include only <mysql.h> [-W#warnings]
  #warning This file should not be included by clients, include only <mysql.h>
   ^

<WARNINGS SNIPPED FOR BREVITY>

_mysql.c:2005:42: error: no member named 'reconnect' in 'struct st_mysql'
      if ( reconnect != -1 ) self->connection.reconnect = reconnect;
                             ~~~~~~~~~~~~~~~~ ^
16 warnings and 1 error generated.
error: command 'cc' failed with exit status 1

----------------------------------------
Failed building wheel for MySQL-python

为简洁起见,我删除了一些警告。你可以在这里看到完整的输出。

标签: pythonpipmysql-python

解决方案


看起来它正在从不兼容的 mariadb 安装中获取标头。

您可能需要安装mysql和/或mysqlclient.

有关详细信息,请参阅: 在 Mac OS X Sierra 上为 Django Python 安装 mysqlclient


推荐阅读