2013-09-18 2 views
0

Когда я запускаю пример gevent, здесь я получаю ошибку импорта. Я использую macos, gevent установлен pip.Ошибка импорта python gevent

Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import gevent 
>>> from gevent import socket 
>>> urls = ['www.google.com', 'www.example.com', 'www.python.org'] 
>>> jobs = [gevent.spawn(socket.gethostbyname, url) for url in urls] 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "gevent/greenlet.py", line 201, in spawn 
    g = cls(*args, **kwargs) 
    File "gevent/greenlet.py", line 75, in __init__ 
    hub = get_hub() 
    File "gevent/hub.py", line 169, in get_hub 
    hub = _threadlocal.hub = hubtype(*args, **kwargs) 
    File "gevent/hub.py", line 268, in __init__ 
    loop_class = _import(self.loop_class) 
    File "gevent/hub.py", line 198, in _import 
    return _import(path[-1]) 
    File "gevent/hub.py", line 210, in _import 
    x = __import__(module) 
ImportError: No module named core 

=========================================== ===================== PS: Когда я устанавливаю gevent, на выходе есть некоторые предупреждения.

[email protected] ~/Code/gevent (master)$ sudo pip install gevent 
Downloading/unpacking gevent 
    Downloading gevent-0.13.8.tar.gz (300kB): 300kB downloaded 
    Running setup.py egg_info for package gevent 

Requirement already satisfied (use --upgrade to upgrade): greenlet in /Library/Python/2.7/site-packages/greenlet-0.4.1-py2.7-macosx-10.8-intel.egg (from gevent) 
Installing collected packages: gevent 
    Running setup.py install for gevent 
    building 'gevent.core' extension 
    clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c gevent/core.c -o build/temp.macosx-10.8-intel-2.7/gevent/core.o 
    clang: warning: argument unused during compilation: '-mno-fused-madd' 
    gevent/core.c:8113:15: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32] 
     __pyx_r = evbuffer_get_length(__pyx_v_self->__pyx___obj); 
       ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    1 warning generated. 
    clang -bundle -undefined dynamic_lookup -Wl,-F. -arch i386 -arch x86_64 build/temp.macosx-10.8-intel-2.7/gevent/core.o -levent -o build/lib.macosx-10.8-intel-2.7/gevent/core.so 
    ld: warning: ignoring file /usr/local/lib/libevent.dylib, file was built for unsupported file format (0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0) which is not the architecture being linked (i386): /usr/local/lib/libevent.dylib 
    Linking /private/tmp/pip_build_root/gevent/build/lib.macosx-10.8-intel-2.7/gevent/core.so to /private/tmp/pip_build_root/gevent/gevent/core.so 

Successfully installed gevent 
Cleaning up... 
+0

Вы пытаетесь установить пакет x86 на машину x64? – Serdalis

+0

@Serdalis Сборка сделана пипсом, я не знаю, почему pip выбрал i386. – Vimos

+0

Еще одна вещь, в python lib gentent, есть core.so, я не могу найти core.py. – Vimos

ответ

1

После использования следующего метода теперь он работает хорошо.

[email protected] ~/Code $ export CFLAGS=-I/opt/local/include 
[email protected] ~/Code $ sudo pip install cython "git+git://github.com/surfly/[email protected]#egg=gevent" 
ystem/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c c-ares/inet_ntop.c -o build/temp.maco