We have a test suite that executes hundreds of Python scripts. After optimizing our own code, we found that most of the test time is now spent on loading numpy and matplotlib. Let's focus here on numpy.
time python3 -c 'import numpy'
gives me 360 ms.
The command
python3 -X importtime -c 'import numpy'
shows that a substantial fraction of that time is spent on loading submodules numpy.fft, numpy.polynomial, numpy.random, which we do not need. Maybe we need not even numpy.lib. How to prevent these submodules from being loaded?
Our naive attempt
python3 -X importtime 'from numpy import core'
brings no improvement; modules other than core are still listed, and the load time is essentially unchanged.