代码之家  ›  专栏  ›  技术社区  ›  Vaibhav Mule

安装MySQL Python会导致命令“CLAN”在Mac OS 103.15上退出状态1失败

  •  13
  • Vaibhav Mule  · 技术社区  · 7 年前

    我已经通过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/
    
    2 回复  |  直到 7 年前
        1
  •  50
  •   sbaxter    6 年前

    我刚在运行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配置 文件下 # 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

        2
  •  2
  •   Steven Zhou    6 年前

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

    我认为这个问题在很多情况下都会发生,主要与安装有关mysql的pip包有关。在我的例子中,我在尝试安装mysqlclient for django时遇到了这个问题。

    当您安装了mysql,并从其官方网站下载了dmg时,这个解决方案应该可以工作。

    那样的话,你会发现 mysql_config 在里面 /usr/local/mysql/bin

    如果是,添加 export PATH="/usr/local/mysql/bin:${PATH}" 在里面 ~/.bash_profile ,这将添加 bin 将mysql文件夹放入路径中,或者可以说 环境变量 . 请注意 mysql 也许在你的mysql版本中有详细说明。对我来说,这条路是 /usr/local/mysql-8.0.12-macos10.13-x86_64/bin .

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

    再次尝试安装关于mysql的pip包。

    如果仍然不工作,则首选重启。

        3
  •  0
  •   NPE_Exception    5 年前

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

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

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