[PYTHON] EC2 / Amazon Linux2: What to do if you get an "unable to execute'gcc': No such file or directory" error with pip install

Overview

When I run pip install -r requirements.txt on EC2 / Amazon Linux2, the following 30 lines of error text are output and the installation fails.

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

...(Abbreviation)...

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.

If you read the error at the bottom, it says ERROR: Command errored out with exit status 1: ~. I found ../scikit-surprise/.. when I scanned it. This is a Python package. This error statement indicates that the installation of scikit-surprise has failed.

Action 1: Install gcc

Just above the above error statement,

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

Is written. I googled this error statement and found an article introducing the solution. It seems that it was improved by installing gcc with the following command.

$ sudo yum install gcc

Execute the command immediately and install again with pip. Result is,

Fatal error: Python.h: No such file or directory
     #include "Python.h"
              ^~~~~~~~~~
Compiling has stopped.
    error: command 'gcc' failed with exit status 1

Another error occurred with Python.h: No such file or directory. Without improvement,

Action 2: Install Python devel

When I googled with scikit-surprise and the error sentence while thinking seriously, almost the same error occurred in GitHub issue There was a person who was terrifying.

There is a stack overflow article in the conversation, and the article says Python. The h: No such file or directory error seems to be caused by the library Python dev not being properly installed. Therefore, it should be improved by executing the following command and installing Python devel.

$ sudo yum install python3-devel

If you run it immediately and install pip,

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

Is displayed and the installation was successful. I did it! !! !! !!

in conclusion

I don't know if it will be useful, but I did a lot of research so I wrote an article. I would be grateful if you could point out any mistakes!

reference

-I got an error when installing Ansible with pip

Recommended Posts

EC2 / Amazon Linux2: What to do if you get an "unable to execute'gcc': No such file or directory" error with pip install
What to do if ENOENT: no such file or directory appears during npm install
What to do if you get a UnicodeDecodeError with pip install
What to do if you get an Undefined error when trying to use pip with pyenv
What to do if you get an error when vagrant up when you enable public_network or private_network on Vagrant + Arch Linux → Install netctl
Workaround if you get an error when trying to install PySide with pip
What to do if you get an error when installing python with pyenv
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if you can't install pyaudio with pip #Python
What to do if you get lost in file reference with FileNotFoundError
What to do if pyenv install does not proceed with an error
What to do if you get an error when trying to load mnist
What to do if you can't install with pip in babun environment
What to do if you get Could not fetch URL 443 with pip
What to do if you get an error when installing Dlib (Ubuntu)
What to do if you get a "No versions found" error in pipenv
What to do when [Errno 2] No such file or directory appears in Python
What to do if you can't pip install mysqlclient
What to do if you get an "unknown service" error from your gRPC server
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do if you run python in IntelliJ and end with an error
What to do when you get an error saying "Name resolution temporarily failed" on linux
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if you get an Undefined error:'Module_six_moves_urllib_parse' object has no attribute'urlencode' on MacOS
What to do if you get an error when running "certbot renew" in CakePHP environment
pip install --upgrade pip will result in No such file or directory
I get an error when trying to install maec 4.0.1.0 with pip
When I try to run the pip command after updating pip, I get "No such file or directory"
What to do if you get an error saying c compiler cannot create executables in configure
What to do if pip --user returns an error in a virtual environment created with pyenv
What to do if you couldn't send an email to Yahoo with Python.
What to do if you get stuck during Anaconda installation on Linux
What to do if an error occurs when importing numpy with VScode
What to do if you get a TypeError with numpy min, max
What to do if you get an error like'Qstring' has already been set to version 1 using mne python
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
[Note] How to deal with unicode error and No such file or directory (output table to excel file with pandas)
Note: What to do if pip install fails
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
What to do if you get angry with swapon failed: Operation not permitted
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
What to do if pip install fails in Xcode 5.1
No module named What to do if you get'libs.resources'
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'
What to do if you get `No kernel for language python found` in Hydrogen
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if you get "(35,'SSL connect error')" in pycurl (one of them)
What to do if you get a Call with too many input arguments error at DoAndReturn in a golang test
What to do if pip install fails to install dependent libraries
What to do if you get an error like dyld: mach-o, but built for simulator or dyld: attempt to run simulator program outside simulator (DYLD_ROOT_PATH not set) in golang
What to do if you get a Cannot retrieve metalink for repository error in yum
[AWS] What to do when you want to pip with Lambda
What to do if you get "coverage unknown" in Coveralls
What to do if you can't sort files with subscripts
What to do when an error occurs with import _ssl
[AWS EC2] Settings you want to do on Amazon Linux 2
What to do if `pip install matplotlib` fails on Mac
What to do if you can't use WiFi on Linux
What to do if Linux VLC can no longer rotate