ImportError: cannot import name core

2,814 views
Skip to first unread message

Jamie

unread,
Feb 20, 2010, 8:34:23 PM2/20/10
to gevent: coroutine-based Python network library
I'm attempting to use gevent for the first time, using a CentOS box.
However, both easy_install and installing it manually appears to be
failing. Building and installing appears to work ok, but when I
attempt "import gevent", I get a traceback that says "ImportError:
cannot import name core."

I have a "core.so" in my site-packages/gevent directory, but I don't
have a "core.py." Am I supposed to?

Denis Bilenko

unread,
Feb 20, 2010, 11:05:57 PM2/20/10
to gev...@googlegroups.com
It's probably because you have an incomplete installation somewhere on
PYTHONPATH.

Check for directories named "gevent" on your filesystem, you'll
probably find one that does not have core.so file.

No, core.so is the right one.

Jamie

unread,
Feb 21, 2010, 12:58:35 AM2/21/10
to gevent: coroutine-based Python network library
Denis, thanks for the help, but I'm not sure I'm getting any closer
to a solution. I've tried installing gevent on three different CentOS
boxes, both with and without virtualenv:

CentOS 5.0 (i686), Python 2.4.3
CentOS 5.2 (i686), Python 2.6.2
CentOS 5.2 (x64), Python 2.6.4

They all fail. CentOS ships with libevent 1.1a, however I couldn't
even get gevent to build correctly using that version. I uninstalled
1.1a using my package manager, downloaded libevent 1.4.13, and
compiled it from source. Gevent now builds correctly, but on every
system I've tried, the import simply does not work.

On Feb 20, 11:05 pm, Denis Bilenko <denis.bile...@gmail.com> wrote:
> It's probably because you have an incomplete installation somewhere on
> PYTHONPATH.
>
> Check for directories named "gevent" on your filesystem, you'll
> probably find one that does not have core.so file.
>

Bob Van Zant

unread,
Feb 21, 2010, 1:10:13 AM2/21/10
to gev...@googlegroups.com
My favorite way to get the ImportError for core is to run python and then
try an import gevent from the build directory. This doesn't work. A cd ..
Always works for me. Trivial, I know, but I've seen it happen to a co-worker
as well.

-Bob

Jamie

unread,
Feb 21, 2010, 1:18:35 AM2/21/10
to gevent: coroutine-based Python network library
Man, I've been trying everything from different servers to weeding
though stacktraces. I figured I was doing something stupid since each
environment was so different. Thanks for posting this today rather
than Monday otherwise my entire weekend would have been
frustrating. :-)

On Feb 21, 1:10 am, Bob Van Zant <b...@veznat.com> wrote:
> My favorite way to get the ImportError for core is to run python and then
> try an import gevent from the build directory. This doesn't work. A cd ..
> Always works for me. Trivial, I know, but I've seen it happen to a co-worker
> as well.
>
> -Bob
>

Denis Bilenko

unread,
Feb 21, 2010, 8:02:52 AM2/21/10
to gev...@googlegroups.com
On Sun, Feb 21, 2010 at 12:10 PM, Bob Van Zant <b...@veznat.com> wrote:
> My favorite way to get the ImportError for core is to run python and then
> try an import gevent from the build directory. This doesn't work. A cd ..
> Always works for me. Trivial, I know, but I've seen it happen to a co-worker
> as well.

Any idea how to prevent this from happening?
One thing that comes to mind is to catch that ImportError and re-raise
it with a more
helpful message.

Bob Van Zant

unread,
Feb 21, 2010, 10:30:08 AM2/21/10
to gev...@googlegroups.com
I'm thinking the best solution would be to make it work and the second best
solution would be to make 'import gevent' force python to go use the gevent
in site-packages.

I'm not quite sure how to make it work. I use setuptools for my Cython
modules and then I get the 'develop' option which makes this use case work
(it drops the .so in the source directory). I wouldn't recommend setuptools
for a project like this since it's yet another dependency and they aren't
super friendly to cython (vs. pyrex) just yet.

To force python to use the one in site-packages you could rename the gevent
directory to like 'src' or something. Then map it in the call to setup()
with a package_dir={'gevent', 'src'}. Unfortunately this doesn't feel very
pythonic. I tried this out and it does solve our problem. In addition to
that package_dir karg to setup() there are two places in setup.py that
explicitly reference the gevent/ directory that need to be changed. Not
worth sending a patch though.

-Bob

Denis Bilenko

unread,
Feb 24, 2010, 1:36:57 AM2/24/10
to gev...@googlegroups.com
On Sun, Feb 21, 2010 at 9:30 PM, Bob Van Zant <b...@veznat.com> wrote:
> I'm thinking the best solution would be to make it work and the second best
> solution would be to make 'import gevent' force python to go use the gevent
> in site-packages.
>
> I'm not quite sure how to make it work. I use setuptools for my Cython
> modules and then I get the 'develop' option which makes this use case work
> (it drops the .so in the source directory). I wouldn't recommend setuptools
> for a project like this since it's yet another dependency and they aren't
> super friendly to cython (vs. pyrex) just yet.

I don't use setuptools, but I do have a symlink from buid/core.so to
gevent/core.so
which has the same effect as setuptools' "develop". I setup PYTHONPATH
to point to the development version of gevent and use it without installing it.

>
> To force python to use the one in site-packages you could rename the gevent
> directory to like 'src' or something. Then map it in the call to setup()
> with a package_dir={'gevent', 'src'}. Unfortunately this doesn't feel very
> pythonic. I tried this out and it does solve our problem. In addition to
> that package_dir karg to setup() there are two places in setup.py that
> explicitly reference the gevent/ directory that need to be changed. Not
> worth sending a patch though.

That's an interesting idea. Unfortunately it breaks the workflow I
described above.
That is, using gevent from working directory rather than from
site-packages becomes
not possible with this.

Maybe hack "./setup.py build" to drop symlink of build/core.so to
gevent/core.so
automatically?

Denis.

Bob Van Zant

unread,
Feb 24, 2010, 1:42:23 AM2/24/10
to gev...@googlegroups.com
On 2/23/10 10:36 PM, "Denis Bilenko" <denis....@gmail.com> wrote:

> Maybe hack "./setup.py build" to drop symlink of build/core.so to
> gevent/core.so
> automatically?

I think that will work. I hesitate to put even more junk into gevent's
setup.py but this might be a worthwhile hack. I manually do something
similar to this for some other package I work on.

I went to PyCon this past weekend and attended at least one talk that
covered python packaging. I walked away with the impression that python
packaging is fundamentally broken and not getting fixed anytime soon. Total
bummer.

-Bob


Denis Bilenko

unread,
Feb 25, 2010, 12:28:18 AM2/25/10
to gev...@googlegroups.com
On Wed, Feb 24, 2010 at 12:42 PM, Bob Van Zant <b...@veznat.com> wrote:
> On 2/23/10 10:36 PM, "Denis Bilenko" <denis....@gmail.com> wrote:
>
>> Maybe hack "./setup.py build" to drop symlink of build/core.so to
>> gevent/core.so
>> automatically?
>
> I think that will work. I hesitate to put even more junk into gevent's
> setup.py but this might be a worthwhile hack. I manually do something
> similar to this for some other package I work on.\

Here's a patch: http://bitbucket.org/denis/gevent/changeset/db27d72a78af/

Please verify that it does not break setup.py in some other way.

Cheers,
Denis.

Bob Van Zant

unread,
Feb 25, 2010, 1:27:03 AM2/25/10
to gev...@googlegroups.com
That patch applied cleanly for me and, best of all, even solved the problem.
In case you want to verify, this is where the link was made to:

core.so ->
/data/crap/xsa_dependencies/gevent-0.12.0/build/lib.linux-x86_64-2.6/gevent/
core.so

-Bob

Ralf Schmitt

unread,
Feb 24, 2010, 5:58:45 AM2/24/10
to gev...@googlegroups.com
Denis Bilenko <denis....@gmail.com> writes:

> I don't use setuptools, but I do have a symlink from buid/core.so to
> gevent/core.so
> which has the same effect as setuptools' "develop".

just a quick tip: You could also run python setup.py build_ext --inplace.

Ludvig Ericson

unread,
Feb 26, 2010, 5:01:53 AM2/26/10
to gev...@googlegroups.com

Wow, that's... Amazing. I had no idea. Thanks for that.

-L

Reply all
Reply to author
Forward
0 new messages