gevent の例を実行すると、ここでインポート エラーが発生します。私は macos を使用しています。gevent は pip によってインストールされます。
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 をインストールすると、出力にいくつかの警告が表示されます。
tanminghuan@bogon ~/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...