Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Right-click on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Mark Hammond <mhammond@sk...> - 2011-10-20 12:26:43
|
On 20/10/2011 6:02 PM, Jason Heeris wrote: > On 20 October 2011 13:37, Mark Hammond<mhammond@...> wrote: >> It might be worth removing that exception clause completely - some other >> "unexpected" ImportError may be causing the problem, so that will let us see >> exactly why that ImportError is happening. > > Removed the clause, and imported crcmod in a console: > >>>> import crcmod > Traceback (most recent call last): > File "<stdin>", line 1, in<module> > File "C:\Python26\lib\site-packages\crcmod\__init__.py", line 9, in<module> > from crcmod.crcmod import * > ImportError: No module named crcmod >>>> > > It just struck me that there *won't* be "crcmod.crcmod" to import, > because the top-level "crcmod" won't be imported until the __init__.py > is run. So the "except" clause is taken, and the usual rules about > taking imports from the current directory should apply (I think... I'm > not quite clear on the edge cases of Python's import mechanism). Yeah - that seems correct. But actually, I thought it was wrong :) As crcmod is importing you will find '"crcmod" in sys.modules' is True, but that import does indeed fail. So I wonder in what cases the ImportError is not thrown? Maybe py3.x - I don't have it on this laptop so can't check and it is getting late for tonight :) > > Anyway, after this change, but WITHOUT 'crcmod' in 'packages', the > build log shows: > > -- [...snip] > byte-compiling C:\Python26\lib\site-packages\crcmod\__init__.py to > crcmod\__init__.pyc > creating C:\Documents and Settings\jason_h\My > Documents\Projects\OscUI\src\build\bdist.win32\winexe\collect-2.6\crcmod > byte-compiling C:\Python26\lib\site-packages\crcmod\_crcfunpy.py to > crcmod\_crcfunpy.pyc > byte-compiling C:\Python26\lib\site-packages\crcmod\crcmod.py to > crcmod\crcmod.pyc > -- [more snip] > The following modules appear to be missing > ['FCNTL', 'OpenSSL', 'System', 'System.IO.Ports', 'TERMIOS', > '_crcfunext', '_zope_interface_coptimizations', 'clr', > 'crcmod.crcmod', 'crcmod.predefined', 'dummy.Process', That is basically expected - py2exe doesn't actually do the import, it just looks for import statements - IOW, it doesn't understand conditional imports. So the question seems to be why the "import predefined" works in Python but not in py2exe? If you can, it would be great to reproduce this. So far I've got the tiny: directory "foo": __init__.py: import sys print "have foo =", "foo" in sys.modules try: from foo.foo import hello except ImportError: from foo import hello foo.py: def hello(): print "hello there" Then: % python -c "import foo; foo.hello()" have foo = True hello there and as in your case, that ImportError branch is indeed taken for the same reason. But, given the time here and the laptop not even having py2exe locally installed, that is as far as I got - but if you (or anyone) can turn that into a failing py2exe program, I'll fix it - or at least determine a work-around :) Cheers, Mark |