[1.5.x] Fixed #21335 -- Use importlib from python3 when using python3

Backport of 3351e94ffa from master.