[Pythonmac-SIG] python 2.7 problem with crcmod -- "ImportError: No module named predefined"

Brendan Simon (eTRIX) brendan.simon at etrix.com.au
Tue May 3 10:37:04 CEST 2011

On 3/05/11 5:01 PM, Ronald Oussoren wrote:
> The crcmod package contains a module named crcmod. My guess is that
> both py2app and py2exe get confused by this and try to fetch
> 'crcmod.predefined' from the nested module instead of the toplevel
> package.  This basicly means that both py2*s have a bug in their
> emulation of the __import__ code.  
>>> I'll see if I can create a testcase for this for the modulegraph
>>> package, it should then be fairly easy to actually fix the issue. As
>>> this is only a problem with python2.7 this may end up being a bug in
>>> the stdlib though.
>>> As a workaround try adding includes for crcmod.predefined, or even
>>> the entire crcmod package (setup(..., package=['crcmod'], ...))
>> Yep.  Forcing inclusion of the module in setup does resolve the
>> issue.  Here is the snippet of my setup file that worked for me :)
>> Hopefully py2app can be fixed so this is not necessary, but at least
>> I have a workaround now.
> I think I can fix this in modulegraph, I'm not quite sure why it works
> in 2.6 but not in 2.7 though. Are you using the same version of crcmod
> in both cases?
> My current impresssion of what's going on here: crcmod.__init__ contains:
> try:
>     from crcmod.crcmod import *
>     import crcmod.predefined
> except ImportError:
>     # Make this backward compatible
>     from crcmod import *
>     import predefined
> A test with a simular package structure fails on both 2.6 and 2.7, but
> works with 3.2. Modulegraph fails because it creates a MissingModule
> node for crcmod.predefined, which seems to indicate a bug in how we
> process imports in a package as it should have created a MissingModule
> node for crcmod.crcmod.predefined for the second import statement and
> then a real node for the last one.
Ah, yes, there are different versions of crcmod installed.

$ /Library/Frameworks/Python.framework/Versions/2.5/bin/pip freeze |
grep crcmod

$ /Library/Frameworks/Python.framework/Versions/2.6/bin/pip freeze |
grep crcmod

$ /Library/Frameworks/Python.framework/Versions/2.7/bin/pip freeze |
grep crcmod

-- Brendan.

More information about the Pythonmac-SIG mailing list