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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50940302/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:39:06  来源:igfitidea点击:

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

pythonmysql-python

提问by Vaibhav Mule

I have installed tools via xcode-select --install but still show the following error while doing pip install MySQL-python

我已经通过 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/

回答by sbaxter

I just resolved this exact issue when running Ansible's mysql_usermodule. The answer herehelped tip me off to a solution. I also needed MySQL-pythonfrom pip, which also broke in this process, so I've added the extra steps.

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

Steps to resolve:

解决步骤:

  1. brew unlink mysql # only if installed, causes the next step to fail
  2. brew install mysql-connector-c
  3. locate mysql_configfile with which (mysql_config)
  4. edit the mysql_configfile, under # Create optionschange this:

    libs="$libs -l "

    to this:

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

    if using vim, :wq!to save the read-only file

  5. Now the install should run successfully

    pip install mysqlclient

  6. Adding this separately, as it's similar but not directly related to the initial question

    pip install MySQL-python

  7. Fix mysqlbrew formula, if it was unlinked in the first step.

    brew unlink mysql-connector-c

    brew link mysql

  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. 修复mysqlbrew 公式,如果它在第一步中未链接。

    brew unlink mysql-connector-c

    brew link mysql

回答by Felipe Fuller Arangua

I fixed it by passing the OpenSSL path:

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

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

You can see the full article of the solution done by MrWeeble

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

回答by NPE_Exception

I solved this issue by setting xcode-select to use non-XCode command line tools, as shown in the below answer. I had a related clangerror which led me to this answer.

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

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

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

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

回答by Steven Zhou

I know maybe the former answers can solve the problem already. But I'm still sharing below solution. If you don't want to brew install any extra things, you can try this solution.

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

I think the issue happens in many situations, mainly related to the installation of the pip packages about MySQL. In my case, I bumped into this issue when trying to install mysqlclient for Django.

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

This solution should work when you've installed MySQL with dmg downloaded from their official site.

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

In that case, you may find mysql_configin /usr/local/mysql/bin

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

If so, add export PATH="/usr/local/mysql/bin:${PATH}"in ~/.bash_profile, this would add the binfolder of mysql into the PATH, or you can say environment variable. Please note that mysqlmaybe in detail with your mysql version. In my case, the path is /usr/local/mysql-8.0.12-macos10.13-x86_64/bin.

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

Save and close the file, then source ~/.bash_profileto enable the change.

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

Try to install the pip package about MySQL again.

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

If still not working, a restart is preferred.

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

回答by Houman

None of these answers are really needed in that length. As Vishal noted it is as easy as

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

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

Then go back to install your pip install -r requirements.txt

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