I feel like there’s probably some built-in method for this, but I suppose one could get the source file and scrape that for import statements, and then check these against available modules (though that wouldn’t catch referenced/imported .NET libraries). A clever regular expression would probably do it, but in principle, something like this maybe:
200417_GHPython_GetImportStatements_00.gh (2.8 KB)
Though this wouldn’t necessarily account for errors (e.g. rhinocsriptsyntax as rs
).