Programming

‘Error Command GCC Failed with Exit Status 1’ – Causes and Fixes

The error message ‘error command GCC failed with exit status 1’ mainly occurs while installing Python-related third-party libraries for starting the compilation process. This error message mostly occurs in Linux or macOS systems while working with ‘Terminal. So, Windows users don’t face such problems because all of their work is GUI-based.

error command ‘GCC’ failed with exit status 1 (Main Image)

This is a GCC compiler and required libraries error. However, the above picture doesn’t represent the complete error message as its remaining part contains the specific library or application name in which it occurs.

Error Message: ‘error command ‘GCC’ failed with exit status 1′ (Title Image)

Reasons for the Occurrence of this Error Message

According to the research we have conducted on this error message, these are the most common reasons for it.

  • GCC is a compiler used in Python for compiling programs. This compiler requires some additional development libraries and when the compiler can’t find the required libraries, it gives an error message. This is the most common reason for the occurrence of this error message.
  • If you’ve faced this error message while installing the Python library software and configuring the PIP source, then the ‘OpenSSL-devel’ might be the cause of this error message.
  • Sometimes users face this error message because of applying Windows binaries to a Linux system. This results in an incompatibility between the module and the library you’re trying to install on your machine. So, it’s better to double-check the requirements before searching for any solutions.

To be noted:

The solution to this error message varies from use case to use case because it occurs in several cases. Therefore, before trying any solution, read the use case mentioned in the explanation of every solution. Because this way, it’ll be easier to relate to your use case and solve this error message.

How to Solve the ‘Error Command GCC Failed with Exit Status 1’ Issue?

As mentioned, this error message has different forms. So, read the solutions carefully and apply them only, if you meet their use case. Otherwise, the solution won’t work for you.

1. While Installing ‘Eventlet’

Here, we’ll first mention the use cases, then we’ll move to the actual method to solve the error message under discussion.

Use Cases

Apply this solution, if you meet the following criteria:

  • If you’re facing a ‘Python.h’ fatal directory error while installing ‘Eventlet’ or any other library.

    Occurrence of ‘error command ‘GCC’ failed with exit status 1′ and facing a ‘Python.h’ fatal directory

OR

  • If you’re facing the error message: ‘error command ‘GCC’ failed with exit status 1 CentOS’ while installing the ‘Eventlet’ library on the system to have the ‘Herd’ for software deployment. In this case, the terminal displays the following error message:

    Occurrence of ‘error command ‘GCC’ failed with exit status 1′ during installing ‘Eventlet’

OR

  • If you’re facing this error message while trying to install some library with the pip command. In this case, people got an error like ‘#include <ffi.h>’ and the compilation terminated by the ‘error: command ‘GCC’ failed with exit status 1.

OR

  • If you’re running the command: ‘docker build –tag python-docker-dev and you’ve faced the error message: ‘error command ‘GCC’ failed with exit status 1 docker.

If your situation meets one of the above-mentioned use cases, then try the following solution.

Actual Method

Note: After every command, you’ll hit the ‘Enter’ key to execute the typed commands.

  1. The first step is to ‘update the version of the GCC compiler’ to the latest version because if you skip this, then you might get errors while executing the main commands. So, type the following commands in the ‘Terminal’ window.
Command for Debian, Kali, Mint and UBUNTU:
sudo apt update gcc
Command for CentOS, Fedora and RHEL:
sudo dnf update gcc
Command for MacOS X:
brew install gcc
  1. Now, you’ll install the ‘Build Essentails’ because these are essential for building the source code of libraries and packages. So, type the following commands in the ‘Terminal’ window.
Command for Debian, Kali, Mint and UBUNTU:
sudo apt install build-essential
Command for CentOS, Fedora and RHEL:
sudo dnf install build-essential
  1. After successful installation of ‘Build Essentials,’ you’ll install the ‘Python Development Packages’ by running the following commands in the ‘Terminal’ window.
Command for Debian, Kali, Mint and UBUNTU:
sudo apt install python-dev

sudo apt install python3-dev (for Python 3 users)
Command for CentOS, Fedora and RHEL:
sudo dnf install python-devel

sudo dnf install python3-devel (for Python 3 users)

Note: In the above command, if you’re using an older Python version, just mention that version number after ‘python,like ‘python2.6-dev’

  1. After running all the commands, if you still get an error that’s talking about installing libevent, then you’ll have to install ‘libevent’ with ‘eventlet. So, type the following commands.
Command for Debian, Kali, Mint and UBUNTU:
sudo apt-get install libevent-dev

Note: You can also use ‘sudo apt install libevent-dev’ in the above command.

Command for CentOS, Fedora and RHEL:
sudo dnf install libevent-devel

Hopefully, this solution will prove useful for you because it has solved the same error message for other users as well.

But if you’re still receiving the same error message on ‘Red Hat Enterprise Linux RPM software package, then try the next solution.

2. For ‘Red Hat Enterprise Linux RPM software package’ Users

Here, we’ll first mention the use cases, then we’ll move to the actual method to solve the error message under discussion.

Use Cases

The use cases for this solution are the same as the above solution. So, if you meet the ‘use cases for ‘Solution # 1, then try the following solution.

Actual Method

If you’re a ‘Red Hat Enterprise Linux RPM software package’ user and the commands of solution # 1 didn’t fix the error message ‘error command ‘GCC’ failed with exit status 1’ for you, then try the following commands in your ‘Terminal’ window.

Note: After every command, you’ll hit the ‘Enter’ key to execute the typed command

For Python 2.7 Users:

If you’re using the 2.7 version of Python, then run the following commands.

sudo yum -y install gcc gcc-c++ kernel-devel

Note: If the above command doesn’t work, then try it by excluding ‘kernel’

sudo yum -y install python-devel

Note: If you want to install the ‘Development Packages, then include ‘libxslt-devel libffi-devel OpenSSL-devel’ after the above command. So, your command will be ‘sudo yum -y install python-devel libxslt-devel libffi-devel OpenSSL-devel’

pip install cryptography

Note: In the above command, the ‘cryptography’ is the name of the ‘python package. So, you can replace it with your own python package’s name

For Python 3.4 Users:

If you’re using the 3.4 version of Python, then run the following commands.

sudo apt-get install python3-dev

pip install ‘your python packet’

Note: In the above command, the ‘your python packet’ will be the name of your own Python package.

3. During Pygame Installation on a macOS system

Here, we’ll first mention the use cases, then we’ll move to the actual method to solve the error message under discussion.

Use Cases

Apply this solution, if you meet the following criteria:

  • If you’ve faced the error command ‘GCC’ failed with exit status 1 pygame while installing the ‘Pygame’ on a MacOS system running Catalina and you have reported this error message as: error command ‘GCC’ failed with exit status 1 mac Catalina.’ The error for this case is:
agk@agk ~ % sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.15.2.pkg -target /
installer: Error - the package path specified was invalid: '/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.15.2.pkg'.

If your situation meets the criteria mentioned above, then try the following solution.

Actual Method

If you’ve faced the same error message on a macOS system while installing the Pygame, then use this method because it has helped the other users as well.

>> xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

>> env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2==2.8.4
Collecting psycopg2==2.8.4
Using cached psycopg2-2.8.4.tar.gz (377 kB)
Installing collected packages: psycopg2
Attempting uninstall: psycopg2
Found existing installation: psycopg2 2.7.7
Uninstalling psycopg2-2.7.7:
Successfully uninstalled psycopg2-2.7.7
Running setup.py install for psycopg2 ... done
Successfully installed psycopg2-2.8.4

Note: If the above didn’t work, then use ‘install psycopg2-binary

4. When trying to Build ‘MySQLdb’ on MacOS X Mountain Lion

Here, we’ll first mention the use cases, then we’ll move to the actual method to solve the error message under discussion.

Use Cases

Apply this solution, if you meet the following criteria:

  • If you have faced the same error message while trying to build ‘MySQLdb’ on a MacOS system running Mountain Lion. In this case, your error message will look like this:
running build

running build_py

copying MySQLdb/release.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb

running build_ext

building '_mysql' extension

gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.6-intel-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64

unable to execute gcc-4.2: No such file or directory

error: command 'gcc-4.2' failed with exit status 1

If your situation meets the criteria mentioned above, then try the following solution.

Actual Method

If you’ve faced the ‘error: command ‘gcc-4.2’ failed with exit status 1’ while trying to build ‘MySQLdb’ on Mac OSX running Mountain Lion, then you can use the following command

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

5. While Installing the ‘python-sane’ Module

Here, we’ll first mention the use cases, then we’ll move to the actual method to solve the error message under discussion.

Use Cases

Apply this solution, if you meet the following criteria:

  • If you’ve faced the same error code while trying to install the ‘python-sane’ module. In this case, the users have reported the following error message:
Occurrence of ‘error command ‘GCC’ failed with exit status 1′ while trying to install the ‘python-sane’ module

If your situation meets the criteria mentioned above, then try the following solution.

Actual Method

If you’ve faced this error message while installing the ‘python-sane’ module, then you can add the ‘libsane-dev’ to your group but exclude the ‘libsane-extras’ package.

6. When Installing ‘psycopg2’

Here, we’ll first mention the use cases, then we’ll move to the actual method to solve the error message under discussion.

Use Cases

Apply this solution, if you meet the following criteria.

  • If you’ve faced the above error with psycopg2 in your Mac. In this case, the error message looks like this:

    Occurrence of ‘error command ‘GCC’ failed with exit status 1′ during installing ‘psycopg2’ on MacOS Mojave

If your situation meets the criteria mentioned above, then try the following solution.

Actual Method

If you’re installing ‘psycopg2’ and you’ve received the error message: ‘error: command ‘/usr/bin/clang’ failed with exit status 1, then you can try the following commands in your code.

brew reinstall openssl

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

Talha Saeed

I am a BSCS graduate and a technology nerd who now loves working and writing about computers and other tech-related stuff. In my free time, I like watching Netflix and playing Cricket 22 and The Witcher 3 (Wild Hunt).
Back to top button