chia-blockchain/chia/util/pip_import.py
2021-04-04 21:41:39 -07:00

18 lines
396 B
Python

"Import a package and install it with PIP if it doesn't exist."
import subprocess
import sys
def pip_import(module, pypi_name=None):
"""
Return None if we can't import or install it.
"""
try:
return __import__(module)
except ImportError:
pass
subprocess.call([sys.executable, "-m", "pip", "install", pypi_name or module])
return __import__(module)