pythonのMySQLdbを入れるまでに起こったエラー
環境
- CentOS6.9
- Python2.6.6
やったこと
サーバーの初期設定とMySQLのインストールは終わったのでPythonの環境整えようとまずはMySQLdbを入れようとした.
そしたら例によってエラー.
標準的な環境でやってるのになんでこんなにあっさりいかないのかなー.
まずは,ググって出たサイト(pipの使い方とインストール - Python入門から応用までの学習サイト)に従ってpipのインストール.
Pythonが古いと文句言われたがこれはすんなり成功した.
Pythonのバージョンの文句はCentOS作ってる方々に言ってほしい.
続いてMySQLdbのインストールを行おうとしたところでエラー発生.
$ sudo pip install MySQL-python DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6 Collecting MySQL-python /usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning. SNIMissingWarning /usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading MySQL-python-1.2.5.zip (108kB) 100% |################################| 112kB 5.3MB/s Complete output from command python setup.py egg_info: sh: mysql_config: command not found Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-build-0cE_wY/MySQL-python/setup.py", line 17, in <module> metadata, options = get_config() File "setup_posix.py", line 43, in get_config libs = mysql_config("libs_r") File "setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-0cE_wY/MySQL-python/
長々と何か言われてるが,mysql_configがないとのこと
ちゃんとMySQL入れてるのにね.
調べたらlibmysqlclient-devを入れろだの書いてあったがyumにそんなものはない.
CentOSの場合はmysql-community-devel.x86_64を入れれば良いらしい.
mysql_confがない場合(mysql-community-serverを使っていて) - Qiita
$sudo yum install mysql-community-devel.x86_64
この記事の人は勘で見つけたみたいなこと書いてるけど勘でわかるものなのか.
これで解決かと思いきや今度はまた別のところでエラー.
[kazuki@tk2-217-18051 tmp]$ pip install MySQL-python DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6 Collecting MySQL-python Using cached MySQL-python-1.2.5.zip Building wheels for collected packages: MySQL-python Running setup.py bdist_wheel for MySQL-python ... error Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-tAYCSR/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 /tmp/tmpHWaMcspip-wheel- --python-tag cp26: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-2.6 copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.6 creating build/lib.linux-x86_64-2.6/MySQLdb copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.6/MySQLdb copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.6/MySQLdb copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.6/MySQLdb copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.6/MySQLdb copying MySQLdb/release.py -> build/lib.linux-x86_64-2.6/MySQLdb copying MySQLdb/times.py -> build/lib.linux-x86_64-2.6/MySQLdb creating build/lib.linux-x86_64-2.6/MySQLdb/constants copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.6/MySQLdb/constants running build_ext building '_mysql' extension creating build/temp.linux-x86_64-2.6 gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -fstack-protector -m64 -fPIC -g -fabi-version=2 -fno-omit-frame-pointer -fno-strict-aliasing _mysql.c:29:20: error: Python.h: No such file or directory _mysql.c:40:26: error: structmember.h: No such file or directory _mysql.c:74: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token ・ ・ ・ error: command 'gcc' failed with exit status 1 ---------------------------------------- Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-QZvTFE/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 /tmp/pip-qD2Kkc-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-QZvTFE/MySQL-python/
長々とエラーメッセージが現れた.
こんだけ長くて重要なのは最後じゃなくて中盤だから困る.
なんかPython.hといういかにもPythonで使うヘッダーが無いとのこと.
ヘッダーが無い時点で処理やめてくれればその後の長々としたエラーメッセージ要らないのに.
今度はpython-develを入れれば良いらしい.
gcc - fatal error: Python.h: No such file or directory - Stack Overflow
$ sudo yum install python-devel
これの後で無事インストールできた.
それにしても必要なものがあっちこっちにあると面倒.
pipくらいは最初から付けてくれてもいいのにな.
Pythonのバージョン上げてーなー
システム破壊しそうだから必要に駆られるまでやらんけど