raise TypeError, "dist must be a Distribution instance"

1,185 views
Skip to first unread message

Paul O. Seidon

unread,
Dec 22, 2014, 12:10:07 PM12/22/14
to cython...@googlegroups.com
Hi all,


I suddenly experience difficulties using Cython (ver. 0.21.1 on Arch Linux,
Python 2.7.9) by the simple

import pyximport; pyximport.install()

It executes properly several times (several pyx modules are imported this
way), but then in

import pyximport
pyximport.install()
import object_finder_strategies_cy

the execution of "import object_finder_strategies_cy" (which is a pyx file)
causes the execution of

raise TypeError, "dist must be a Distribution instance"

in the __init__ method of class Command.

The sequence in question is

# late import because of mutual dependence between these classes
from distutils.dist import Distribution

if not isinstance(dist, Distribution):
raise TypeError, "dist must be a Distribution instance"
if self.__class__ is Command:
raise RuntimeError, "Command is an abstract class"

Looking at dist reveals that it is an instance of
distutils.dist.Distribution. But Distribution (the 2nd arg in
isinstance(dist, Distribution)) suddenly is setuptools.dist.Distribution
instead of distutils.dist.Distribution as it has been in the other imports.

Can anyone shed some light on this? How do I overcome this problem?

Cheers
Paul



Paul O. Seidon

unread,
Dec 24, 2014, 2:53:39 AM12/24/14
to cython...@googlegroups.com
Read somewhere, that setuptools.dist.Distribution is an improved
distutils.dist.Distribution. In the hope, that it's Liskov complete, I
commented out the instance check. Worx for now.

Cheers
Paul

Stefan Behnel

unread,
Dec 26, 2014, 5:32:49 AM12/26/14
to cython...@googlegroups.com
I created a CPython issue:

http://bugs.python.org/issue23114

Meanwhile, we can work around this problem by postponing the import. It
only fails if the Distribution class is imported before setuptools.

Stefan

Caleb Hattingh

unread,
Jan 5, 2015, 1:01:50 AM1/5/15
to cython...@googlegroups.com, stef...@behnel.de
On Friday, December 26, 2014 8:32:49 PM UTC+10, Stefan Behnel wrote:
I created a CPython issue:
http://bugs.python.org/issue23114
Meanwhile, we can work around this problem by postponing the import. It
only fails if the Distribution class is imported before setuptools.

I am fixing my own setup.py files (by importing setuptools early), but what can we do now to fix cythonmagic and similar automated invocations of cython? I've updated my Anaconda Python to 2.1.0, IPython to 2.3.1,  Cython to 0.21.2 and setuptools to 7 (this is the latest available through the default conda channel apparently). I would prefer to avoid downgrading anything if possible, but if necessary I will have to.  I use cythonmagic quite a lot.

Caleb Hattingh

unread,
Jan 5, 2015, 5:43:26 PM1/5/15
to cython...@googlegroups.com, stef...@behnel.de
Ok. My cythonmagic.py in IPython 2.3.1 still has all the stuff implemented, the commit that calls the implementation of the magic in Cython itself is not included in 2.3.x apparently, so I'll just `import setuptools` at the top of cythonmagic.py.  I think that will fix it for now. 
Reply all
Reply to author
Forward
0 new messages