The stellar initial mass distribution function (IMF) is the most crucial assumption when interpreting the astronomy observations of stellar systems. Evidence has shown that the IMF is not universal nor invariant. In this talk, I will introduce the IGIMF theory that explains and predicts the IMF variation as a function of star formation intensity and gas metallicity. The galaxy-wide IMF can be calculated accordingly using the open-source GalIMF code (Python3 https://github.com/Azeret/galIMF) we developed. The application of IGIMF on the galaxy chemical evolution of massive elliptical galaxies and ultra-faint dwarf galaxies have shown excellent agreement with observation, providing the best explanation of the element abundance for these galaxies so far.