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

时间:2018-06-20 04:38:03

标签: python 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/

5 个答案:

答案 0 :(得分:40)

运行Ansible的mysql_user模块时,我刚刚解决了这个确切的问题。答案here帮助我提出了解决方案。我还需要MySQL-python中的pip,该过程也中断了,因此我添加了额外的步骤。

解决步骤:

  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 unlink mysql-connector-c

    brew link mysql

答案 1 :(得分:4)

我通过将xcode-select设置为使用非XCode命令行工具来解决了此问题,如以下答案所示。我遇到了一个相关的clear input str2 State Year Industry Employment AL 2014 1 123345 AL 2015 1 145411 AL 2016 1 149402 AL 2014 2 153518 AL 2015 2 157773 AL 2016 2 163156 AK 2014 1 167187 AK 2015 1 167863 AK 2016 1 163320 AK 2014 2 162419 AK 2015 2 166116 AK 2016 2 170136 end egen id = group(State) reshape wide Employment, i(id Year) j(Industry) drop id order State Year Employment* list, abbreviate(15) sepby(State) +------------------------------------------+ | State Year Employment1 Employment2 | |------------------------------------------| 1. | AK 2014 167187 162419 | 2. | AK 2015 167863 166116 | 3. | AK 2016 163320 170136 | |------------------------------------------| 4. | AL 2014 123345 153518 | 5. | AL 2015 145411 157773 | 6. | AL 2016 149402 163156 | +------------------------------------------+ 错误,导致我找到了这个答案。

clang

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

答案 2 :(得分:2)

我通过传递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

答案 3 :(得分:1)

我知道以前的答案可能已经解决了问题。但我仍在分享以下解决方案。如果您不想酿造任何多余的东西,可以尝试此解决方案。

我认为这个问题在很多情况下都会发生,主要与安装有关MySQL的pip软件包有关。就我而言,在尝试为Django安装mysqlclient时遇到了这个问题。

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

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

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

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

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

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

答案 4 :(得分:1)

在此长度范围内,这些答案中的任何一个都不需要。正如维沙尔(Vishal)指出的那样,它就像

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

然后返回以安装您的pip install -r requirements.txt