You can also use something like:
import pip
def install(package):
if hasattr(pip, 'main'):
pip.main(['install', package])
else:
pip._internal.main(['install', package])
# Example
if __name__ == '__main__':
install('argh')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…