Check if a python module is installed or not using a script, Check python module installation

When working with python development, plenty of modules come into picture. There are times wherein python developers/users are not sure about certain modules being installed.This script can be used to check if the module is installed or not.
_VERSION_ - attribute may be defined for some scripts. For some scripts, this might give out an error.
try:
import modulename
except ImportError:
print "modulename is not installed"
else:
print "modulename is installed"
print "with version", getattr (modulename, __VERSION__, "unknown")
For example, to check if the html/xml parser module BeautifulSoup is installed run,

try:
import BeautifulSoup
except ImportError:
print "soup is not installed"
else:
print "soup is installed"
print "with version", getattr (soup, __VERSION__, "unknown")