如何在Mac OS X Lion上安装Python库“gevent”

Python库gevent ,版本0.13.6(PyPI上的当前版本)不会pip install在OS X Lion,Python 2.7(也可能是其他版本)上。它在Snow Leopard上工作正常。

我怎样才能安装这个库?

如果可以使用pip install ,而不是手动或自定义进程来完成,那么奖励点数将会与自动构build完美搭配。

这是我的pip install输出:

 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 

不要发布整个事情! 这太多了! 90%的时间,第一个错误就够了

 gevent / libevent.h:9:19:error:event.h:没有这样的文件或目录

这意味着没有安装提供event.h头文件的库。 图书馆被称为libevent( 网站 )。

一般来说,像这样的编译错误在构build脚本中是一个缺陷。 构build脚本应该给出一个错误消息libevent没有安装,这是一个错误,它没有这样做。

从MacPorts获得libevent,然后用CFLAGS环境variables手动告诉编译器,在运行pip时在哪里findevent.hlibevent

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

你也可以用homebrew来安装libevent: brew install libevent
(来自David Wolever的评论)

 CFLAGS='-std=c99' pip install gevent 

请参阅: 无法安装gevent OSX 10.11

在OS X 10.11上,clang使用c11作为默认值,所以只要把它转回到c99即可。

过了一段时间,我意识到上面提到的CFLAGSvariables的path在从端口安装libevent时起作用,而不是在brew中起作用。 以下为我工作(在OSX小牛):

 $ 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 

这是我find最简单的方法:

使用自制软件安装libevent

 $ brew install libevent 

安装gevent

 $ pip install gevent 

这是我能做到的唯一方法。

在Snow Leopard上寻找帮助时find了这个答案,张贴这个以防其他人以这种方式出现同样的问题。

我通过macports安装了libevent。

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

我已经通过brew安装了libevent,并且也失败了,什么工作类似于Stephen所做的,但是指向brew默认安装:

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

如果你安装所有来源和使用csh,下面的工作在Mac OS 10.9上

  1. 下载最新稳定的http://libevent.org/ libevent-2.0.21-stable

    • 。/configuration
    • 使
    • sudo make install
  2. virtualenv env

  3. 源env / bin / activate.csh

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

  5. 点安装gevent

我使用virtualenv和virtualenv包装,所以我想这是自包含的。 我有gevent这样工作:

假设你有虚拟的env设置,那么:

 workon {my_virtual_env} 

然后下载libevent并将其安装在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 

我假设你已经安装了gcc 5+(我使用brew)

希望这可以帮助。

 sudo pip install cython git+git://github.com/gevent/gevent.git#egg=gevent