LoginSignup
12
3

More than 3 years have passed since last update.

EC2/Amazon Linux2: pip installで"unable to execute 'gcc': No such file or directory"エラーが起きた時の対処

Posted at

概要

EC2/Amazon Linux2でpip install -r requirements.txtを実行したところ、以下の30行ぐらいのエラー文が出力されインストールが失敗する。

ERROR: Command errored out with exit status 1:
     command: /home/my-user/.venvs/my_app/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ok4gp9ve/scikit-surprise/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ok4gp9ve/scikit-surprise/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-record-d52oris6/install-record.txt --single-version-externally-managed --compile --install-headers /home/my-user/.venvs/my_app/include/site/python3.7/scikit-surprise
         cwd: /tmp/pip-install-ok4gp9ve/scikit-surprise/
    Complete output (53 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/surprise

...(略)...

creating build/temp.linux-x86_64-3.7/surprise
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/home/my-user/.venvs/my_app/lib64/python3.7/site-packages/numpy/core/include -I/home/my-user/.venvs/my_app/include -I/usr/include/python3.7m -c surprise/similarities.c -o build/temp.linux-x86_64-3.7/surprise/similarities.o
    unable to execute 'gcc': No such file or directory
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/my-user/.venvs/my_app/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ok4gp9ve/scikit-surprise/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ok4gp9ve/scikit-surprise/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-record-d52oris6/install-record.txt --single-version-externally-managed --compile --install-headers /home/my-user/.venvs/my_app/include/site/python3.7/scikit-surprise Check the logs for full command output.

一番下のエラー読むと、ERROR: Command errored out with exit status 1: ~と記述あり。流し読みしてると../scikit-surprise/..を発見。これはPythonのパッケージです。
今回のエラー文は、scikit-surpriseのインストールが失敗していることを示しています。

対処1: gccをインストール

上記エラー文の少し上に、

unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1

と書かれてます。このエラー文でググって解決方法を紹介してる記事を発見。
gccを以下のコマンドでインストールし改善されたそうです。

$ sudo yum install gcc

早速コマンドを実行し再度pipでインストール。
結果は、

致命的エラー: Python.h: No such file or directory
     #include "Python.h"
              ^~~~~~~~~~
    コンパイルを停止しました。
    error: command 'gcc' failed with exit status 1

Python.h: No such file or directoryと別のエラーが発生。改善せず、、

対処2: Python develをインストール

まじかーーーーと思いながらscikit-surpriseとエラー文を合わせてググったところ、GitHubのissueでほぼ同じエラーが生じてる方がいました。

やりとりの中でstack overflowの記事があり、記事によるとPython.h: No such file or directoryエラーは、Python devというライブラリが適切にインストールされてないことが原因で生じるそうです。
よって以下のコマンドを実行し、Python develをインストールすることで改善されるはずです。

$ sudo yum install python3-devel

早速実行しpipインストールすると、

Installing collected packages: scikit-surprise
    Running setup.py install for scikit-surprise ... done
Successfully installed scikit-surprise-1.1.1

と表示され、無事インストールできました。やったーーーー!!!!

おわりに

役に立つかわからないんですが、せっかく色々調べたので記事にしました。
間違いがあれば指摘していただけると嬉しいです!

参考

12
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
3