252

I wanted to install Eventlet on my system in order to have "Herd" for software deployment, but the terminal is showing a GCC error (as root):

cd ~
easy_install -U eventlet

Output:

Searching for eventlet
Reading http://pypi.python.org/simple/eventlet/
Reading http://wiki.secondlife.com/wiki/Eventlet
Reading http://eventlet.net
 Best match: eventlet 0.9.16
  Processing eventlet-0.9.16-py2.7.egg
  eventlet 0.9.16 is already the active version in easy-install.pth

Using /usr/local/lib/python2.7/dist-packages/eventlet-0.9.16-py2.7.egg
Processing dependencies for eventlet
Searching for greenlet>=0.3

Reading http://pypi.python.org/simple/greenlet/
Reading https://github.com/python-greenlet/greenlet
Reading http://bitbucket.org/ambroff/greenlet
Best match: greenlet 0.3.4
Downloading http://pypi.python.org/packages/source/g/greenlet/greenlet-   0.3.4.zip#md5=530a69acebbb0d66eb5abd83523d8272
Processing greenlet-0.3.4.zip
Writing /tmp/easy_install-_aeHYm/greenlet-0.3.4/setup.cfg
Running greenlet-0.3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-_aeHYm/greenlet-0.3.4/egg-dist-tmp-t9_gbW
In file included from greenlet.c:5:0:
greenlet.h:8:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'gcc' failed with exit status 1`

Why can't Python.h be found?

19 Answers 19

416

Your install is failing because you don't have the Python development headers installed.

First, update the packages with sudo apt update.

You can do this through APT on Ubuntu/Debian with:

sudo apt-get install python-dev

For Python 3, use:

sudo apt-get install python3-dev

For eventlet you might also need the libevent libraries installed so if you get an error talking about that you can install libevent with:

sudo apt-get install libevent-dev
Sign up to request clarification or add additional context in comments.

12 Comments

FWIW, you definitely need both python-dev and libevent-dev. Thanks!
For fedora, you can use: sudo yum install python-devel
I suggest running sudo apt-get update before running these 2 commands. I was getting error with sudo apt-get install python-dev.
I have the same error but have python-devel installed and system is updated with yum -y install updates.. what else could the issue be?
yum install python3-devel
|
58

For Fedora:

sudo yum install python-devel

sudo yum install libevent-devel

and finally:

sudo easy_install gevent

1 Comment

sudo yum install python-devel sudo yum install libevent-devel worked for me
43

This worked for me on CentOS:

sudo yum -y install gcc
sudo yum install python-devel

3 Comments

solved my problem too. unable to execute 'gcc': No such file or directory error: command 'gcc' failed with exit status 1
use sudo yum install python34-devel for python 3.x as the other is only for python 2.x
I was looking everywhere for this. Using RHEL 7 and gcc is not included by default anymore.
35

For Red Hat versions (CentOS 7), use the below command to install a Python development package

Python 2.7

sudo yum install python-dev

or

sudo yum install python-devel

Python 3.4

sudo yum install python34-devel

Python 3.6

sudo yum install python36-devel

If the issue is still not resolved, then try installing the below packages:

sudo yum install python-devel

sudo yum install openssl-devel

sudo yum install libffi-devel

2 Comments

No package python-dev available. I am getting this.
It should be python-devel in CentOS
22

On macOS, I had trouble installing fbprophet which requires pystan which requires gcc to compile. I would consistently get the same error: command 'gcc' failed with exit status 1

I think I fixed the problem for myself thus:

I used brew install gcc to install the newest version, which ended up being gcc-8.

Then I made sure that when gcc ran, it would use gcc-8 instead.

It either worked, because I added alias gcc='gcc-8 in my .zshrc (the same as .bashrc, but for Z shell (executable zsh)), or because I ran export PATH=/usr/local/bin:$PATH (see this comment).

Also: all my attempts were inside a virtual environment, and I only succeeded by installing fbprophet globally (with pip), but I still didn't have any success inside a venv

1 Comment

The most helpful answer! Exporting PATH did the trick
9

If it is still not working, you can try this

sudo apt-get install build-essential

in my case, it solved the problem.

2 Comments

Solved my problem with the shap library on Ubuntu 20.04.
this solution work with JPype1 library on python:3.8.13-slim
7

I just run into the same problem on AWS EC2 installing regex. This is working perfectly for me:

sudo yum -y install gcc

And next

sudo yum -y install gcc-c++

Comments

5

Try this:

sudo apt-get install libblas-dev libatlas-base-dev

I had a similar issue on Ubuntu 14.04 (Trusty Tahr). For me, the following Ubuntu packages.

2 Comments

Re "the following Ubuntu packages": That ought to be fixed. For example, is something missing? Please respond by editing (changing) the answer, not here in comments (but please, *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** without *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** "Edit:", "Update:", or similar )
OK, the OP has left the building ("Last seen more than 3 years ago").
5

On macOS, I also had problems trying to install fbprophet which had gcc as one of its dependencies.

After trying several steps as recommended by Boris, the command below from the Facebook Prophet project page worked for me in the end.

conda install -c conda-forge fbprophet

It installed all the needed dependencies for fbprophet. Make sure you have Anaconda installed.

2 Comments

Thank you! This gcc is causing me so many install issues that I still have not resolved and Boris steps wouldn't work for me either but that did the trick. Thank you!
yep, similarly in my case for marisa-trie it worked: conda install -c conda-forge python-marisa-trie
4

This page is going to save your life, for all further library issues that are forthcoming,

For Alpine Linux (3.6 or later), use

apk --update --upgrade add gcc musl-dev jpeg-dev zlib-dev libffi-dev cairo-dev pango-dev gdk-pixbuf-dev

2 Comments

Sounds like an overkill of dependencies to me and added ~200 MB - what has ``WeasyPrint` to do with that? But I have to state that this is the onlz thing that helped me with an Issue related to ansible in a jenkins container.
@Cadoiz enjoy :)
3

For openSUSE 42.1 Leap Linux, use this:

sudo zypper install python3-devel

1 Comment

Welcome to Stack Overflow. Note that this is as much of a comment as an answer. There are a number of comments under the main answers which describe alternatives for different Linux distros. I realize you can't make comments yet. Be cautious about adding 'answers' to well-established questions which are really 'comments'.
3

For CentOS 7.2:

LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID:    CentOS
Description:    CentOS Linux release 7.2.1511 (Core)
Release:    7.2.1511
Codename:    Core

Install Eventlet:

sudo yum install python-devel
sudo easy_install -ZU eventlet

Terminal information:

As root:

cd ~
easy_install -ZU eventlet

Output:

Searching for eventlet
Reading http://pypi.python.org/simple/eventlet/
Best match: eventlet 0.19.0
Downloading https://pypi.python.org/packages/5a/e8/ac80f330a80c18113df0f4f872fb741974ad2179f8c2a5e3e45f40214cef/eventlet-0.19.0.tar.gz#md5=fde857181347d5b7b921541367a99204
Processing eventlet-0.19.0.tar.gz
Running eventlet-0.19.0/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Hh9GQY/eventlet-0.19.0/egg-dist-tmp-rBFoAx
Adding eventlet 0.19.0 to easy-install.pth file

Installed /usr/lib/python2.6/site-packages/eventlet-0.19.0-py2.6.egg
Processing dependencies for eventlet
Finished processing dependencies for eventlet

2 Comments

When I run, it gives me the error "unable to execute 'gcc': No such file or directory"
@Sarang that means you haven't install gcc yet, execute:"yum -y install gcc"
2

I am using macOS v10.15.4 (Catalina). None of the posted solutions worked for me. This worked for me:

xcode-select --install

Output:

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

And:

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2==2.8.4

Output:

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

Use pip3 for python3.

Comments

1

If you are on a Mac, as myself, try this in your terminal:

xcode-select --install

Then accept the installation request, and it works afterwards as described in this issue.

Comments

1

Use:

sudo apt install gcc

It works for PyCharm on Ubuntu 20.10 (Groovy Gorilla).

Comments

0

Similarly I fixed it like this (notice python34):

sudo yum install python34-devel

Comments

0

Build from source and install, this is fixed in the latest release (10.3+):

mkdir -p /tmp/install/netifaces/
cd /tmp/install/netifaces && wget -O "netifaces-0.10.4.tar.gz" "https://pypi.python.org/packages/source/n/netifaces/netifaces-0.10.4.tar.gz#md5=36da76e2cfadd24cc7510c2c0012eb1e"
tar xvzf netifaces-0.10.4.tar.gz
cd netifaces-0.10.4 && python setup.py install

Comments

0

If you are migrating to a more modern version of Python 3, e.g., Python 3.5 to Python 3.8, you may want to check/upgrade the versions of the library that are failing if you have already installed the recommended libraries to handle GCC building python3-dev and other libraries as suggested.

It depends on the package. Some versions of the packages may not be supported on later versions of Python 3.

Comments

0

On a macOS system, if the message

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
...

is part of the error log, installing the developer tools could solve this issue.

The following terminal command can run the developer tools software installation:

xcode-select --install

I encountered a similar issue while installing greenlet, and the above resolved it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.