Problem that pip install cannot be done with pyenv + Yosemite (error: command'clang' failed with exit status 1)

Introduction

When using pyenv on Mac OS X Yosemite (10.10 or later), I came across a library that I can't pip install.

Problems and solutions can already be found at https://github.com/yyuu/pyenv/issues/273.

It's English, so when I was impatient, I couldn't get into my head at all, and sometimes I got hooked on the bog, so I'll write it here in Japanese.

Method

problem

When I try to include MySQL-python, I get the following error:

$ pip install MySQL-python==1.2.5
Collecting MySQL-python==1.2.5
/Users/nii/.pyenv/versions/project_name/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: MySQL-python
  Running setup.py bdist_wheel for MySQL-python
  Complete output from command /Users/nii/.pyenv/versions/project_name/bin/python -c "import setuptools;__file__='/private/var/folders/kp/c6tk2jws71xcncdjhsj7ww8r_shv_8/T/pip-build-w4jYAD/MySQL-python/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /var/folders/kp/c6tk2jws71xcncdjhsj7ww8r_shv_8/T/tmpMQMhmppip-wheel-:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.10-x86_64-2.7
  copying _mysql_exceptions.py -> build/lib.macosx-10.10-x86_64-2.7
  creating build/lib.macosx-10.10-x86_64-2.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
  creating build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.macosx-10.10-x86_64-2.7
  clang -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.6.23/include/mysql -I/Users/nii/.pyenv/versions/2.7.6/include/python2.7 -c _mysql.c -o build/temp.macosx-10.10-x86_64-2.7/_mysql.o -g -fno-omit-frame-pointer -fno-strict-aliasing
  In file included from _mysql.c:44:
  /usr/local/Cellar/mysql/5.6.23/include/mysql/my_config.h:348:11: warning: 'SIZEOF_SIZE_T' macro redefined [-Wmacro-redefined]
    #define SIZEOF_SIZE_T  SIZEOF_LONG
            ^
  /Users/nii/.pyenv/versions/2.7.6/include/python2.7/pymacconfig.h:43:17: note: previous definition is here
  #        define SIZEOF_SIZE_T          8
                  ^
  In file included from _mysql.c:44:
  /usr/local/Cellar/mysql/5.6.23/include/mysql/my_config.h:442:9: warning: 'HAVE_WCSCOLL' macro redefined [-Wmacro-redefined]
  #define HAVE_WCSCOLL
          ^
  /Users/nii/.pyenv/versions/2.7.6/include/python2.7/pyconfig.h:908:9: note: previous definition is here
  #define HAVE_WCSCOLL 1
          ^
  _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
          if (how < 0 || how >= sizeof(row_converters)) {
              ~~~ ^ ~
  3 warnings generated.
  clang -bundle -bundle_loader python.exe -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/nii/.pyenv/versions/2.7.6/lib build/temp.macosx-10.10-x86_64-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.6.23/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.10-x86_64-2.7/_mysql.so
  ld: file not found: python.exe
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  error: command 'clang' failed with exit status 1

  ----------------------------------------
  Failed building wheel for MySQL-python
Failed to build MySQL-python
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python
    Complete output from command /Users/nii/.pyenv/versions/project_name/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/kp/c6tk2jws71xcncdjhsj7ww8r_shv_8/T/pip-build-w4jYAD/MySQL-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/kp/c6tk2jws71xcncdjhsj7ww8r_shv_8/T/pip-TU73Hn-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/nii/.pyenv/versions/project_name/include/site/python2.7/MySQL-python:
    running install
    running build
    running build_py
    copying MySQLdb/release.py -> build/lib.macosx-10.10-x86_64-2.7/MySQLdb
    running build_ext
    building '_mysql' extension
    clang -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.6.23/include/mysql -I/Users/nii/.pyenv/versions/2.7.6/include/python2.7 -c _mysql.c -o build/temp.macosx-10.10-x86_64-2.7/_mysql.o -g -fno-omit-frame-pointer -fno-strict-aliasing
    In file included from _mysql.c:44:
    /usr/local/Cellar/mysql/5.6.23/include/mysql/my_config.h:348:11: warning: 'SIZEOF_SIZE_T' macro redefined [-Wmacro-redefined]
      #define SIZEOF_SIZE_T  SIZEOF_LONG
              ^
    /Users/nii/.pyenv/versions/2.7.6/include/python2.7/pymacconfig.h:43:17: note: previous definition is here
    #        define SIZEOF_SIZE_T          8
                    ^
    In file included from _mysql.c:44:
    /usr/local/Cellar/mysql/5.6.23/include/mysql/my_config.h:442:9: warning: 'HAVE_WCSCOLL' macro redefined [-Wmacro-redefined]
    #define HAVE_WCSCOLL
            ^
    /Users/nii/.pyenv/versions/2.7.6/include/python2.7/pyconfig.h:908:9: note: previous definition is here
    #define HAVE_WCSCOLL 1
            ^
    _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
            if (how < 0 || how >= sizeof(row_converters)) {
                ~~~ ^ ~
    3 warnings generated.
    clang -bundle -bundle_loader python.exe -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/nii/.pyenv/versions/2.7.6/lib build/temp.macosx-10.10-x86_64-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.6.23/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.10-x86_64-2.7/_mysql.so
    ld: file not found: python.exe
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/Users/nii/.pyenv/versions/project_name/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/kp/c6tk2jws71xcncdjhsj7ww8r_shv_8/T/pip-build-w4jYAD/MySQL-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/kp/c6tk2jws71xcncdjhsj7ww8r_shv_8/T/pip-TU73Hn-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/nii/.pyenv/versions/project_name/include/site/python2.7/MySQL-python" failed with error code 1 in /private/var/folders/kp/c6tk2jws71xcncdjhsj7ww8r_shv_8/T/pip-build-w4jYAD/MySQL-python

It seems that paramiko was not included in the linked issues. There were some other libraries that I couldn't install, though I won't list them here.

Solution

The problem is with the python version. The version of python in the environment that gave this error was 2.7.6. If you upgrade to 2.7.8 or higher, you can include the library.

I confirmed same happens on my OS X 10.10.1, at least, with CPython 2.7.6 and 2.7.7. This might be a build issue of paramiko package itself, though, I couldn't find any related issues on the project. Upgrading to CPython 2.7.8 will fix the issue.

The solution is written in English at the link, so if you read it calmly, you can reach the solution.

Recommended Posts

Problem that pip install cannot be done with pyenv + Yosemite (error: command'clang' failed with exit status 1)
Measures that pip install cannot be done with pycharm or import ssl cannot be done
Error with pip install
Import libraries that cannot be pip installed with PyCharm
When I try to install mysqlclient with Django, I get error: command'gcc' failed with exit status 1.
Options when installing libraries that cannot be piped with pyenv
[Corrective Measures] error: [WinError 2] The specified file cannot be found. ERROR: Command errored out with exit status 1
Install packages that need to be compiled with Python3 with pip [Windows]
SSL certificate related with pip install? Error
Items that cannot be imported with sklearn
Python environment settings (virtualenv + pip cannot be done)
Investigation when import cannot be done with python
List packages that can be updated with pip
PIL cannot be installed by virtualenv with pyenv
The problem that the ifconfig command cannot be used
Workaround for the problem that UTF-8 Japanese mail cannot be sent with Flask-Mail (Python3)