I would like to use scipy.spatial.distance.cosine in my code. I can import the spatial submodule if I do something like import scipy.spatial<
That's because scipy is a package, not a module. When you import a package, you don't actually load the modules inside, and thus package.module causes an error.
However, import package.module would work, because it loads the module, not the package.
This is the standard behavior for most import statements, but there are a few exceptions.
Here is the same case for urllib in Python 3:
>>> import urllib
>>> dir(urllib)
['__builtins__', '__cached__', '__doc__', '__file__', '__initializing__', '__loader__', '__name__', '__package__', '__path__', 'error', 'parse', 'request', 'response']
See? there is no submodules there. To access its submodule, we ask for the submodule:
>>> import urllib.request
>>>
Hope this simple explanation helps!