Use the included pkg_resources
library to detect if setuptools
is available and if so, what version it is. If you cannot import pkg_resources
, there is no setuptools
library installed, full stop:
try:
import pkg_resources
except ImportError:
print "No setuptools installed for this Python version"
else:
dist = pkg_resources.get_distribution('setuptools')
print dist.project_name, dist.version
The project name is either distribute
or setuptools
; for me this prints:
>>> import pkg_resources
>>> dist = pkg_resources.get_distribution('setuptools')
>>> print dist.project_name, dist.version
distribute 0.6.32
See the Distribution
attributes documentation for further details on what information is available.