Re: [cx-freeze-users] ImportError: cannot import name format with python 3.2, numpy 1.6.0, cx_freez
Brought to you by:
atuining
From: Anthony T. <ant...@gm...> - 2011-06-23 04:24:15
|
On Wed, Jun 22, 2011 at 5:51 PM, Dave McGary <DM...@ja...> wrote: > I finally got my project (inherited) to build on WinXP with cx_freeze > 4.2.3 win32, python 2.6. > > My script runs fine on my WinXP box, so everything required is installed > properly, but cx_freeze said it was unable to find some modules. > > I noticed that some of the modules reported ass missing were in fact in > place in my python instasll AND in the build folder. Just where they > should be. And yet cx_freeze refuses to let the build complete and run. Hmm, that seems strange indeed. > It turns out that some of the modules were imported inside a try: except: > block. This confuses cx_freeze, but works fine at runtime, both frozen > and not-frozen. cx_Freeze uses static analysis and so only notices an import statement. It can't really know that it is inside a try...except block without disassembling the code and then the likelihood of getting it wrong is probably not worth the attempt -- at least I think so. :-) > @Kosta Whenever you get the "Missing Modules notifications", cx_freeze > STOPS the build. It intentionally prevents the result from working (via > 'ImportError()' or 'self._RunHook("missing"...'), even if it was mistaken > about the missing modules! Hmm, no, that is not true. The only time that is the case is if you include it directly in includes in your configuration file. If the module is included via some import statement in one of your scripts or a module that one of your scripts imports then it simply reports the fact and goes along its merry way. > You can try to let the build complete, and see if your app will run. Just > go into finder.py and yank the following code: > > # if module not found, track that fact > if module is None: > if caller is None: > raise ImportError("No module named %r" % name) > self._RunHook("missing", name, caller) > if returnError and name not in caller.ignoreNames: > callers = self._badModules.setdefault(name, {}) > callers[caller.name] = None > > > After commenting out that code, I was able to build and run the app. That code is needed. Do you have a script that you can send me that I can run and use to test myself? I'm intrigued by your report and would like to know why you found it necessary to do what you did! > There are still issues, but it is running now. > > Note that this is not really a fix for the problem, the commented out code > is necessary if you want to be told about any missing modules. Running > the script _before_ you freeze it is the BEST way to know that you have > everything installed properly. > > I have found that there is a bug in cx_freeze, but I do not know enough > about cx_freeze to fix it properly. Well, as the author I know enough to fix it....just not enough at the moment to know how to replicate it. :-) I have frozen numpy and matplotlib a number of times without difficulty. If you can provide a script that should help a lot. Thanks in advance. Anthony |