centos7 psycopg2のインストールエラー
sudo pip3.6 install psycopg2のエラー
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-70sqru_l/psycopg2/
以上のようなエラーが出た。この問題には以下のように解決する。
pip install --upgrade pip setuptools
上記コマンドを実行し、Successfully installed setuptools-41.0.0にアップグレード。再びpsycopg2のインストールを試みると次のエラーが出た。
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-kegfrwd6/psycopg2/
エラーが若干変わったと思いきや、同じ場所で引っかかっている気もする。
ググり方をエラー内容ではなく"centos psycopg2 error"で調べたら以下が出てきた。
https://stackoverflow.com/questions/12908807/cant-install-psycopg2-on-centos
これによると以下2コマンドを実行してみることと書いてあった。
yum install python-devel yum install postgresql-devel
これらを実行してもpsycopg2はインストールできなかった。
./psycopg/psycopg.h:34:20: fatal error: Python.h: No such file or directory #include <Python.h>
このようなエラーが出てきたので次のように検索をかけて、解決案を探した。検索内容:./psycopg/psycopg.h:34:20: fatal error: Python.h: No such file or directory centos7
解決案:https://stackoverflow.com/questions/21530577/fatal-error-python-h-no-such-file-or-directory
For yum (CentOS, RHEL...): sudo yum install python-devel # for python2.x installs sudo yum install python34-devel # for python3.4 installs
そこで# yum install python36-develとした。その次にpsycopg2をインストールする事ができた。
少し振り返る
何が何だか分からなかったけれども、最初のエラーでは
Error: pg_config executable not found. pg_config is required to build psycopg2 from source. Please add the directory containing pg_config to the $PATH or specify the full executable path with the option:
これが原因だった。これについてはこれが参考になると思われる。http://kumagonjp2.blog.fc2.com/blog-entry-204.html
次のエラーで./psycopg/psycopg.h:34:20: fatal error: Python.h: No such file or directory #include Python.hと出たのに対してはpython-develがないことが原因らしい。自分の場合はpython3.6だったので,yum install python36-develとしたらクリアできた。