Thanks for your suggestions Chris and Terry.
The answer I was looking for is the modulefinder module which is part of
the standard lib. Works like a charm!
Quote: This module provides a ModuleFinder class that can be used to
determine the set of modules imported by a script. modulefinder.py can
also be run as a script, giving the filename of a Python script as its
argument, after which a report of the imported modules will be printed.
Note there's a similar module for Python 2.7.