import sys
import pkg_resources
import warnings
import numbers

import six


def get_version(modulename):
    "Return a string containing the module name and the library version."
    version = '?'

    # Get the root module name (in case we have something like `recipy.open`
    # or `matplotlib.pyplot`)
    modulename = modulename.split('.')[0]

    if modulename in sys.modules:
        ws = pkg_resources.working_set
        package = ws.find(pkg_resources.Requirement(modulename))
        version = package.version
    else:
        warnings.warn('requesting version of a module that has not been '
                      'imported ({})'.format(modulename))

    # If we get some kind of crazy object (ie. not a string or a number)
    # then ignore it
    if not isinstance(version, (six.string_types, numbers.Number)):
        version = '?'

    return '{} v{}'.format(modulename, version)

@@ -388,65 +388,36 @@
     
-ws = pkg_resources.working_set%0A        package = ws.find(
+version = _get_version_from_
 pkg_
@@ -429,20 +429,8 @@
 rces
-.Requirement
 (mod
@@ -437,17 +437,16 @@
 ulename)
-)
 %0A       
@@ -438,32 +438,35 @@
 lename)%0A        
+if 
 version = packag
@@ -462,24 +462,73 @@
 on =
- package.version
+= '?':%0A            version = _get_version_from_module(modulename)
 %0A   
@@ -848,24 +848,24 @@
 sion = '?'%0A%0A
-
     return '
@@ -900,8 +900,906 @@
 ersion)%0A
+%0A%0Adef _get_version_from_pkg_resources(modulename):%0A    ws = pkg_resources.working_set%0A    package = ws.find(pkg_resources.Requirement(modulename))%0A    try:%0A        version = package.version%0A    except AttributeError:%0A        version = '?'%0A    return version%0A%0A%0Adef _get_version_from_module(modulename):%0A    version = '?'%0A    mod = sys.modules%5Bmodulename%5D%0A    try:%0A        version = mod.__version__%0A    except (AttributeError, TypeError, KeyError):%0A        pass%0A    try:%0A        version = mod.version%0A    except (AttributeError, TypeError, KeyError):%0A        pass%0A    try:%0A        version = mod.version.version%0A    except (AttributeError, TypeError, KeyError):%0A        pass%0A    try:%0A        version = mod.VERSION%0A    except (AttributeError, TypeError, KeyError):%0A        pass%0A    try:%0A        version = mod.version()%0A    except (AttributeError, TypeError, KeyError):%0A        pass%0A%0A    return version%0A

Add fallback method for finding library versions