share
Stack OverflowHow can I install the Python library 'gevent' on Mac OS X Lion
[+64] [10] Jacob Lyles
[2011-10-03 01:33:34]
[ python macos osx-lion gevent ]
[ https://stackoverflow.com/questions/7630388/how-can-i-install-the-python-library-gevent-on-mac-os-x-lion ]

Python library gevent, version 0.13.6 (the current version on PyPI) will not pip install on OS X Lion, Python 2.7 (and probably others.) It works fine on Snow Leopard.

How can I get this library installed?

Bonus points if it can be done using pip install, rather than a manual or custom process, because then it will play nicely with automated builds.

Here is my pip install output:

pip install gevent
Downloading/unpacking gevent
  Running setup.py egg_info for package gevent

Requirement already satisfied (use --upgrade to upgrade): greenlet in ./tl_env/lib/python2.7/site-packages (from gevent)
Installing collected packages: gevent
  Running setup.py install for gevent
    building 'gevent.core' extension
    gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c gevent/core.c -o build/temp.macosx-10.6-intel-2.7/gevent/core.o
    In file included from gevent/core.c:225:
    gevent/libevent.h:9:19: error: event.h: No such file or directory
    gevent/libevent.h:38:20: error: evhttp.h: No such file or directory
    gevent/libevent.h:39:19: error: evdns.h: No such file or directory
    gevent/core.c:361: error: field ‘ev’ has incomplete type
    gevent/core.c:741: warning: parameter names (without types) in function declaration
    gevent/core.c: In function ‘__pyx_f_6gevent_4core___event_handler’:
    gevent/core.c:1619: error: ‘EV_READ’ undeclared (first use in this function)
    gevent/core.c:1619: error: (Each undeclared identifier is reported only once
    gevent/core.c:15376: warning: assignment makes pointer from integer without a cast
   [... about 1000 more lines of compiler errors...]
    gevent/core.c:15385: error: dereferencing pointer to incomplete type
    gevent/core.c: In function ‘__pyx_pf_6gevent_4core_4http___init__’:
    gevent/core.c:15559: warning: assignment makes pointer from integer without a cast
    gevent/core.c: At top level:
    gevent/core.c:21272: error: expected ‘)’ before ‘val’
    lipo: can't figure out the architecture type of: /var/folders/s5/t94kn0p10hdgxzx9_9sprpg40000gq/T//cczk54q7.out
    error: command 'gcc-4.2' failed with exit status 1
    Complete output from command /Users/jacob/code/toplevel/tl_env/bin/python -c "import setuptools;__file__='/Users/jacob/code/toplevel/tl_env/build/gevent/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/s5/t94kn0p10hdgxzx9_9sprpg40000gq/T/pip-s2hPd3-record/install-record.txt --install-headers /Users/jacob/code/toplevel/tl_env/bin/../include/site/python2.7:
    running install

running build

running build_py

running build_ext

building 'gevent.core' extension

gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c gevent/core.c -o build/temp.macosx-10.6-intel-2.7/gevent/core.o
(1) pypi.python.org/packages/source/g/gevent/gevent-0.13.6.tar.g‌​z download it here. and install using sudo python setup.py install -I /opt/local/include -L /opt/local/lib. Assuming you have installed libevent via Macports atleast. - meson10
(16) Closing this as 'not a real question' is extraordinarily unhelpful. It might not meet some abstract criteria of 'realness', but being able to find this page and read the supplied answers just saved me a whole bunch of time. - Jonathan Hartley
The new version of gevent, currently 1.0beta, is available on google code, and no longer relies on libevent. It installs fine on OSX, although you have to download the sdist and install manually, because it isn't on PyPI yet. - Jonathan Hartley
I know this is an older post, but I also found stackoverflow.com/questions/32417141/… helpful for problems installing gevent on OSX 10.10.5. Specifically, using CFLAGS='-std=c99' pip install gevent will use an older, compatible compiler. The new question isn't a duplicate per se, but I also don't want people to waste as much time as I did chasing unrelated solutions. - akosel
[+114] [2011-10-03 01:38:09] Dietrich Epp [ACCEPTED]

Don't post the entire thing! That's too much! 90% of the time, the first error is enough...

gevent/libevent.h:9:19: error: event.h: No such file or directory

This means that the library which provides the event.h header is not installed. The library is called libevent ( website [1]).

In general, compilation errors like these are a flaw in the build scripts. The build script should give an error message that libevent is not installed, and it is a bug that it did not do so.

To get libevent from MacPorts and then manually tell compiler with CFLAGS environment variable where to find event.h and libevent while running pip.

sudo port install libevent
CFLAGS="-I /opt/local/include -L /opt/local/lib" pip install gevent

You can also use homebrew for installing libevent : brew install libevent
(from David Wolever's comment)

[1] http://libevent.org/

(43) Just to add: you can install libevent with homebrew using brew install libevent - David Wolever
(9) By definition, the person asking the question is not qualified to judge which parts of the output are important, and hence they should always post the entire thing. Otherwise, important details sometimes get omitted. - Jonathan Hartley
The new version of gevent, currently 1.0beta, is available on google code, and no longer relies on libevent. It installs fine on OSX, although you have to download the sdist and install manually, because it isn't on PyPI yet. - Jonathan Hartley
@JonathanHartley: I don't see your logic. Whenever you build software, the first error you encounter is always an error, and subsequent errors may just be consequences of that error. For the sake of only trying to solve one error at a time, just post the first error from a build log. You show me a case where you need to see multiple build errors to figure out what's going on, and I'll show you the exception to the rule. - Dietrich Epp
@Deitrich: Hey. I concede that only the first error is the pertinent one when looking strictly at C compiler output. When I made my comment I was thinking more in the general case of output from arbitrary processes, where the definition of 'error' is more wooly. e.g, pip output (containing compiler output) might contain compile errors which are then ignored, as the library install falls back to a pure Python implementation, or disables optional features, etc. This 'error' in the output will likely have no effect on users, whereas subsequent messages in the pip output might be more relevant. - Jonathan Hartley
(1) @Mikael Lepistö: Does that actually work? There's no -L flag, so I think you would get a link error. - Dietrich Epp
@Dietrich Epp: It did work on my Lion yesterday. Linker flags were already correct in build scripts so there was no need to modify LDFLAGS. - Mikael Lepistö
(1) I had the same experience as @DietrichEpp and needed to CFLAGS="-I /opt/local/include -L /opt/local/lib" on Lion - Kristian Glass
(1) @KristianGlass: Since you confirmed my expectations, I edited it in. I suspect Mikael Lepistö may have some customized environment variables or something like that. - Dietrich Epp
On Mac I needed to write CFLAGS="-I/opt/local/include -L/opt/local/lib" pip install gevent. Notice that there is no space after -L and -I. - Marboni
1
[+24] [2015-10-30 06:38:06] Legolas Bloom
CFLAGS='-std=c99' pip install gevent

See in: Can't install gevent OSX 10.11 [1]

on OS X 10.11, clang uses c11 as the default, so just turn it back to c99.

[1] https://stackoverflow.com/questions/32417141/cant-install-gevent-osx-10-11

2
[+18] [2013-10-24 19:02:51] Ramiro Berrelleza

After a while, I realized that the paths for the CFLAGS variable mentioned above works when installing libevent from port, but not from brew. The following worked for me (on OSX Mavericks):

$ brew install libevent
$ export CFLAGS="-I /usr/local/Cellar/libevent/2.0.21/include -L /usr/local/Cellar/libevent/2.0.21/lib"
$ pip install gevent

wish there were second answer acceptability. The original answer seems based of of macports rather than homebrew. This solved for me. Thanks. - Lukas
It sets a few c-compiler flags needed for pip to be able to build and install gevent (en.wikipedia.org/wiki/CFLAGS) - Ramiro Berrelleza
3
[+6] [2013-08-09 00:34:21] sandman

This is the way I found the easiest:

install libevent using homebrew

$ brew install libevent

install gevent

$ pip install gevent

This was the only way I could get it to work.


(1) I get "ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)" when I run: brew install libevent - brianray
4
[+4] [2013-02-23 18:45:22] Stephen

Found this answer when looking for help installing on Snow Leopard, posting this in case someone else comes this way with the same problem.

I had libevent installed via macports.

export CFLAGS=-I/opt/local/include export LDFLAGS=-L/opt/local/lib sudo pip install gevent


I have libevents installed via macports but I get same error with this commands - hithwen
5
[+2] [2013-08-27 20:43:32] Mauricio Souza Lima

I had libevent installed via brew and it failed too, what worked was similar to what Stephen done, but pointing to brew default install:

CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib pip install gevent


6
[0] [2013-10-26 22:25:55] nbari

In case you install all from sources and use csh the following works on mac os 10.9

  1. download latest stable http://libevent.org/ libevent-2.0.21-stable

    • ./configure
    • make
    • sudo make install
  2. virtualenv env

  3. source env/bin/activate.csh

  4. setenv CFLAGS "-I /usr/local/include -L /usr/local/lib"

  5. pip install gevent


7
[0] [2015-09-06 01:58:46] silverdagger

I use virtualenv and virtualenv wrapper, and so I wanted this to be self contained. I got gevent working like so:

Assuming you have virtual env setup, then:

workon {my_virtual_env}

Then download libevent and install it against the virtualenv.

curl -L -O https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

tar -xzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix="$VIRTUAL_ENV"
make && make install

I'm assuming you've got gcc 5+ installed (I use brew)

Hope this helps.


8
[0] [2015-09-20 08:02:40] user200778
sudo pip install cython git+git://github.com/gevent/gevent.git#egg=gevent

(1) Consider describing what your are suggesting and the reasons for the same. - pradyunsg
9
[0] [2018-09-23 16:30:10] sandip

I am using MacOs High Sierra (10.13.3) First I did : brew install libevent

I upgraded my pip version to pip-18.0. then tried installing again with following :-

pip install gevent

it worked.


10