はじめに
Mac OS X Yosemite ( 10.10 以降)で pyenv を使っていると、 pip install できないライブラリに出くわしました。
問題と解決方法は https://github.com/yyuu/pyenv/issues/273 に既にあります。
英語なので、焦っていると全く頭に入ってこず、泥沼にハマってしまうことがあったので、ここに日本語で書いておきます。
方法
問題
MySQL-python を入れようとすると、以下のようなエラーになります。
$ 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
リンク先の issues では paramiko が入らなかったようですね。
ここでは挙げませんが、他にもインストールできないライブラリが何個かありました。
解決方法
問題は python のバージョンに問題があります。
このエラーが出た環境の python のバージョンは 2.7.6 でした。
2.7.8 以上にバージョンを上げると、ライブラリを入れることができます。
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.
リンク先では英語で解決方法が書かれてありますので、落ち着いて読んでいけば解決まで辿り着けます。