4 ms·
> In principle generating dependencies from a notebook should be as easy as parsing the ast, finding all the import statements, and then using sys to lookup wha
by Galanwe 6y ago
> In principle generating dependencies from a notebook should be as easy as parsing the ast, finding all the import statements, and then using sys to lookup what package provided that module.
Well not really.
First, there is no link between a distribution package name (what you install with pip) and python package name (what you import).
e.g. The distribution package "foobar" can install the python package "baz". Well, it's even worst than that. There could be name space packages so multiple distribution package actually install parts of a python package. And there could be monkey patching.
Second, Python is not a static language. The import system is part of the interpretation of python code, and as such, is dynamic.
You have absolutely 0 guarantee that "import foo" on two different environments, even if they have the same version of package foo, will produce the same results. There could be an infinite amount of magic done in foo's __init__ that depend on other libraries being installed, etc.
Third, don't get me started on the actual version of these libraries.