mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-11-11 01:28:17 +03:00
18 lines
396 B
Python
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)
|