When installing or building a Python package, you might get an error saying:
error: Setup script exited with error: command 'gcc' failed with exit status 1
This error occurs when Python can’t find the GNU Compiler Collection (GCC) and other related libraries that are required to build the package successfully.
The GCC is used by Python to compile a package that uses the C programming language, which is the language used to write the Python interpreter.
Writing a Python library in C is a common practice by developers to improve the performance of the library, but you need the GCC to compile the library.
To resolve this error, you can try installing GCC on your computer:
# Debian\Linux sudo apt-get install gcc # REHL\Fedora\CentOS sudo yum install gcc # Arch\Manjaro sudo pacman -S gcc # macOS brew install gcc
If that doesn’t work, then try installing the Python development package as well:
# Debian\Linux sudo apt-get install python-dev sudo apt-get install python3-dev # REHL\CentOS\Fedora sudo dnf install python-devel sudo dnf python3-devel # Arch\Manjaro sudo pacman -S python3 cmake
The development package should help you get the build process up and running.
If the build still returns an error, then try installing the build package that includes GCC and G++ compilers:
# Debian\Linux sudo apt-get install build-essentials # REHL\CentOS\Fedora sudo dnf group install "Development Tools" # Arch\Manjaro sudo pacman -Sy base-devel
That should take care of any error that occurs when you compile the Python C libraries.
If you use Windows, you need to get the Microsoft Visual C++ Build Tools which you can download here.
Once the build tools are installed, run the installation or build command again. Notice that you didn’t receive the error this time.
For macOS, the Python development package and build tools should already be included when you install Python.
Otherwise, use Homebrew to get the latest version of Python for Mac.
I hope this tutorial helps. Have fun coding!