[Tutor] testing for modules?

Kent Johnson kent37 at tds.net
Tue Oct 25 00:35:05 CEST 2005

Ed Hotchkiss wrote:
> i have a generic script that is using several modules on windows and 
> linux boxes. i need to have the scripts test if a module is installed, 
> and then if not - then to install the module. can anyone give me a 
> headsup on how to test for a module, returning something to indicate 
> whether or not it is installed, then after that executing file to 
> install the module.? just somewhere to start would be helpful! thanks in 
> advance.

I don't know a generic way to install a module but the testing part is easy - just try to import it:
  import mymodule
except ImportError:
  # install mymodule

In general you need to download and unzip a module, then run 'python setup.py install'.


More information about the Tutor mailing list