Why some package can import a module that does *not* exist in the folder that it means to import from?

51 views Asked by At

When I try to look at the implementation of some numpy functions, I realized a strange thing (description below).

In this python script: /Users/myname/opt/anaconda3/envs/ml/lib/python3.7/site-packages/numpy/core/multiarray.py

Inside this file: from numpy.core._multiarray_umath import *

However, when I go to the folder to check, I also use terminal to ls all files under the that folder /Users/myname/opt/anaconda3/envs/ml/lib/python3.7/site-packages/numpy/core, the _multiarray_umath is not included in any of the file under that folder, as shown below:

__init__.py
__pycache__
_add_newdocs.py
_aliased_types.py
_asarray.py
_dtype.py
_dtype_ctypes.py
_dummy.cpython-37m-darwin.so
_exceptions.py
_internal.py
_methods.py
_multiarray_tests.cpython-37m-darwin.so
_multiarray_umath.cpython-37m-darwin.so
_operand_flag_tests.cpython-37m-darwin.so
_rational_tests.cpython-37m-darwin.so
_string_helpers.py
_struct_ufunc_tests.cpython-37m-darwin.so
_type_aliases.py
_ufunc_config.py
_umath_tests.cpython-37m-darwin.so
arrayprint.py
cversions.py
defchararray.py
einsumfunc.py
fromnumeric.py
function_base.py
generate_numpy_api.py
getlimits.py
include
info.py
lib
machar.py
memmap.py
multiarray.py
numeric.py
numerictypes.py
overrides.py
records.py
setup.py
setup_common.py
shape_base.py
tests
umath.py
umath_tests.py

I'm really confused how such mechanism works? Can you please explain it with plain English and also point me to some resources that I can learn the motivation behind all such package development practice?

0

There are 0 answers