繁体   English   中英

在 Mac OS 10.13.15 上安装 MySQL-python 导致命令“clang”失败,退出状态为 1

[英]Installing MySQL-python causes command 'clang' failed with exit status 1 on Mac OS 10.13.15

我已经通过 xcode-select --install 安装了工具,但在执行pip install MySQL-python时仍然显示以下错误

Building wheels for collected packages: MySQL-python
  Running setup.py bdist_wheel for MySQL-python ... error
  Complete output from command /Users/vaibhavmule/Envs/switchidea/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/p6/0v0bflxn3t399_qdpnm2z7hc0000gn/T/pip-install-SD9Cgh/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/p6/0v0bflxn3t399_qdpnm2z7hc0000gn/T/pip-wheel-g6C50k --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.13-x86_64-2.7
  copying _mysql_exceptions.py -> build/lib.macosx-10.13-x86_64-2.7
  creating build/lib.macosx-10.13-x86_64-2.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
  creating build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.macosx-10.13-x86_64-2.7
  clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/Cellar/mysql/8.0.11/include/mysql -I/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.13-x86_64-2.7/_mysql.o
  _mysql.c:36:10: fatal error: 'my_config.h' file not found
  #include "my_config.h"
           ^~~~~~~~~~~~~
  1 error generated.
  error: command 'clang' failed with exit status 1

  ----------------------------------------
  Failed building wheel for MySQL-python
  Running setup.py clean for MySQL-python
Failed to build MySQL-python
django-model-utils 3.0.0 has requirement Django>=1.8, but you'll have django 1.6.7 which is incompatible.
faker 0.8.16 has requirement six>=1.10, but you'll have six 1.6.1 which is incompatible.
django-phonenumber-field 2.0.0 has requirement Django>=1.11, but you'll have django 1.6.7 which is incompatible.
Installing collected packages: MySQL-python, opbeat, olefile, Pillow, pyzmq, contextlib2, raven, simplejson, South, sqlparse, wheel, django-sendfile, httplib2, pytz, twilio, phonenumberslite, babel, django-phonenumber-field, django-twilio, text-unidecode, python-dateutil, Faker, factory-boy, waitress, beautifulsoup4, WebOb, webtest, django-webtest, coverage
  Running setup.py install for MySQL-python ... error
    Complete output from command /Users/vaibhavmule/Envs/switchidea/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/p6/0v0bflxn3t399_qdpnm2z7hc0000gn/T/pip-install-SD9Cgh/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 /private/var/folders/p6/0v0bflxn3t399_qdpnm2z7hc0000gn/T/pip-record-ihy3we/install-record.txt --single-version-externally-managed --compile --install-headers /Users/vaibhavmule/Envs/switchidea/bin/../include/site/python2.7/MySQL-python:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13-x86_64-2.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.13-x86_64-2.7
    creating build/lib.macosx-10.13-x86_64-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb
    creating build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-x86_64-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.13-x86_64-2.7
    clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/Cellar/mysql/8.0.11/include/mysql -I/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.13-x86_64-2.7/_mysql.o
    _mysql.c:36:10: fatal error: 'my_config.h' file not found
    #include "my_config.h"
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/Users/vaibhavmule/Envs/switchidea/bin/python2.7 -u -c "import 
setuptools, tokenize;__file__='/private/var/folders/p6/0v0bflxn3t399_qdpnm2z7hc0000gn/T/pip-install-SD9Cgh/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 /private/var/folders/p6/0v0bflxn3t399_qdpnm2z7hc0000gn/T/pip-record-ihy3we/install-record.txt --single-version-externally-managed --compile --install-headers /Users/vaibhavmule/Envs/switchidea/bin/../include/site/python2.7/MySQL-python" failed with error code 1 in /private/var/folders/p6/0v0bflxn3t399_qdpnm2z7hc0000gn/T/pip-install-SD9Cgh/MySQL-python/

我刚刚在运行 Ansible 的mysql_user模块时解决了这个确切的问题。 这里的答案帮助我找到了解决方案。 我还需要来自pip MySQL-python ,它也在这个过程中中断,所以我添加了额外的步骤。

解决步骤:

  1. brew unlink mysql # only if installed, causes the next step to fail
  2. brew install mysql-connector-c
  3. 找到mysql_config文件, which (mysql_config)
  4. 编辑mysql_config文件,在# Create options更改:

    libs="$libs -l "

    对此:

    libs="$libs -lmysqlclient -lssl -lcrypto"

    如果使用 vim, :wq! 保存只读文件

  5. 现在安装应该成功运行

    pip install mysqlclient

  6. 单独添加这个,因为它相似但与最初的问题没有直接关系

    pip install MySQL-python

  7. 修复mysql brew 公式,如果它在第一步中未链接。

    brew unlink mysql-connector-c

    brew link mysql

我通过传递 OpenSSL 路径修复了它:

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install mysqlclient

您可以查看 MrWeeble 完成的解决方案的完整文章

我通过将 xcode-select 设置为使用非 XCode 命令行工具解决了这个问题,如下面的答案所示。 我有一个相关的clang错误导致我得到这个答案。

sudo xcode-select --switch /Library/Developer/CommandLineTools

https://stackoverflow.com/a/30902106/11614142

我知道也许以前的答案已经可以解决问题了。 但我仍然在下面分享解决方案。 如果你不想 brew install 任何额外的东西,你可以试试这个解决方案。

我觉得这个问题出现在很多情况下,主要是关于MySQL的pip包的安装。 就我而言,我在尝试为 Django 安装 mysqlclient 时遇到了这个问题。

当您使用从其官方站点下载的 dmg 安装 MySQL 时,此解决方案应该可以工作。

在这种情况下,您可能会在/usr/local/mysql/bin找到mysql_config

如果是这样,在~/.bash_profile添加export PATH="/usr/local/mysql/bin:${PATH}" ,这会将 mysql 的bin文件夹添加到 PATH 中,或者您可以说环境变量 请注意mysql可能与您的 mysql 版本有关。 就我而言,路径是/usr/local/mysql-8.0.12-macos10.13-x86_64/bin

保存并关闭文件,然后source ~/.bash_profile以启用更改。

再次尝试安装有关 MySQL 的 pip 包。

如果仍然无法正常工作,则首选重新启动。

在这么长的时间里,这些答案中没有一个是真正需要的。 正如 Vishal 所指出的那样简单

brew install openssl 
LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient

然后回去安装你的pip install -r requirements.txt

那么首先什么是clang 它是 C、C++ 的“编译器前端”。 您可能会问什么是编译器前端? 有关更多详细信息,请参阅此答案 您正在尝试安装一个库( mysqlclientapache-airflow[mysql]或任何其他),需要找到一些C++ 依赖项,但没有,因此消息如下:

    #include "my_config.h"
             ^~~~~~~~~~~~~

clang错误消息非常冗长,因此您可能会错过重要信息。 重要的是这 3 行:

    ld: library not found for -lzstd
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'clang' failed with exit status 1

在“command 'clang' failed”之前找到第一行,这会告诉你没有找到什么库。

如果未找到该库,则可能是因为它未安装(因此所有brew install ...都在这里回答)或因为在路径中找不到它(因此所有export LDFLAGS=...export LIBRARY_PATH=...答案)。

就我而言,没有找到 2 个库,但都安装了,所以我解决了:

export LDFLAGS="-L/usr/local/Cellar/openssl@1.1/1.1.1l/lib -L/usr/local/Cellar/zstd/1.5.0/lib"
pip install 'apache-airflow[mysql]'

这不是对 OP 的直接回答,但希望在某种程度上有所帮助。

我试过这个,

export ARCHFLAGS="-arch x86_64"

然后重新执行安装命令。 已经为我解决了。

以下对我有用,使用 mac。

brew install leveldb gmp pkg-config

在这之后运行

pip3 install MySQL-python

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM