How to test if a module exists?

Jon Dufresne jon.dufresne at
Tue Nov 9 19:06:39 CET 2010

On Tue, Nov 9, 2010 at 4:30 AM, Roy Smith <roy at> wrote:
> In article <ibatkk$t7p$4 at>,
>  Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
>> In message <roy-4C92BB.16523506112010 at>, Roy Smith wrote:
>> > On the other hand, if your module's bug is that it in turn imports some
>> > other module, which doesn't exist, you'll also get an ImportError.
>> Does it really matter? Either way, the module is unusable.
> If I understand correctly, he's trying to differentiate between:
> 1) The module is unusable because it's not installed
> 2) The module is unusable because it has a bug in it.

Yes. Case 1 is an acceptable case. In case 1, if the extension module
(extension as in extension to my core program) does not have
then the extension adds no behavior in the magic1 portion of the
program. However, if the extension does have but it is buggy
(case 2), I want my program to fail. Currently I am doing this using
the traceback code suggested in an earlier post.

More information about the Python-list mailing list