python - 为什么 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
为简洁起见,我删除了一些警告。你可以在这里看到完整的输出。
解决方案
看起来它正在从不兼容的 mariadb 安装中获取标头。
您可能需要安装mysql
和/或mysqlclient
.
有关详细信息,请参阅: 在 Mac OS X Sierra 上为 Django Python 安装 mysqlclient
推荐阅读
- c# - 在 C# 中转换为另一种类型的自定义结构
- azure-functions - 有没有办法查看 Durable Function Sub Orchestration 的状态?
- rabbitmq - 如何允许用户只声明队列?
- mysql - 如何在 MySQL 中存储派生列
- laravel - 如何在 Laravel + Vue 中修复“未找到此相关模块”
- python - 在 Python 中将突出显示的文本复制到剪贴板
- excel - Power Query 十进制值未加载
- http - 发送到 Squid 的相同请求,但在使用 masscan 时收到 400 Bad Request 错误
- javascript - 为什么将 time 与 moment.js 进行比较失败?
- c# - 如何检查 DatagrGridView 是否有新行 c#