from pip._internal import main as pipmain pipmain(['install', 'package-name'])
https://stackoverflow.com/a/51704613