How can I install the Python library 'gevent' on Mac OS X Lion

37,760

Solution 1

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).

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)

Solution 2

CFLAGS='-std=c99' pip install gevent

See in: Can't install gevent OSX 10.11

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

Solution 3

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

Solution 4

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.

Solution 5

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

Share:
37,760
Jacob Lyles
Author by

Jacob Lyles

Updated on March 09, 2020

Comments

  • Jacob Lyles
    Jacob Lyles about 4 years

    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
    
  • David Wolever
    David Wolever over 12 years
    Just to add: you can install libevent with homebrew using brew install libevent
  • Jonathan Hartley
    Jonathan Hartley almost 12 years
    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
    Jonathan Hartley almost 12 years
    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.
  • Dietrich Epp
    Dietrich Epp almost 12 years
    @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.
  • Jonathan Hartley
    Jonathan Hartley almost 12 years
    @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.
  • Dietrich Epp
    Dietrich Epp almost 12 years
    @Mikael Lepistö: Does that actually work? There's no -L flag, so I think you would get a link error.
  • Mikael Lepistö
    Mikael Lepistö almost 12 years
    @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.
  • Kristian Glass
    Kristian Glass almost 12 years
    I had the same experience as @DietrichEpp and needed to CFLAGS="-I /opt/local/include -L /opt/local/lib" on Lion
  • Dietrich Epp
    Dietrich Epp almost 12 years
    @KristianGlass: Since you confirmed my expectations, I edited it in. I suspect Mikael Lepistö may have some customized environment variables or something like that.
  • Marboni
    Marboni over 11 years
    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.
  • hithwen
    hithwen about 11 years
    I have libevents installed via macports but I get same error with this commands
  • brianray
    brianray over 10 years
    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
  • Lukas
    Lukas about 10 years
    wish there were second answer acceptability. The original answer seems based of of macports rather than homebrew. This solved for me. Thanks.
  • pradyunsg
    pradyunsg over 8 years
    Consider describing what your are suggesting and the reasons for the same.
  • ari
    ari over 7 years
    It sets a few c-compiler flags needed for pip to be able to build and install gevent (en.wikipedia.org/wiki/CFLAGS)