I would like to check if all modules imported by a script are installed before I actually run the script, because the script is quite complex and is usually running for many hours. Also, it may import different modules depending on the options passed to it, so just running it once may not check everything. So, I wouldn't like to run this script on a new system for few hours only to see it failing before completion because of a missing module.
Apparently, pyflakes and pychecker are not helpful here, correct me if I'm wrong. I can do something like this:
$ python -c "$(cat *.py|grep import|sed 's/^\s\+//g'|tr '\n' ';')"
but it's not very robust, it will break if the word 'import' appears in a string, for example.
So, how can I do this task properly?
grep '^\s*import', because no Python line may start with import (correct me if I'm wrong).from <module> import <stuff>? No, any regex-based solution will be too brittle. The best way is to work at the AST-level not the textual level which is what snakefood, linked in my previous comment, does(or at least claims to, never tried it)pip installand get all your depends at once.