Skip to content

Instantly share code, notes, and snippets.

@qizhihere
Last active October 3, 2016 06:20
Show Gist options
  • Save qizhihere/1e8772b9149c434abfe221234740c3f6 to your computer and use it in GitHub Desktop.
Save qizhihere/1e8772b9149c434abfe221234740c3f6 to your computer and use it in GitHub Desktop.
Python helper functions.
def has_pkg(package):
import importlib
try:
importlib.import_module(package)
except ImportError:
return False
return True
def pip_install(package):
import pip
pip.main(['install', package])
def ensure_pkg(package):
has_pkg(package) or pip_install(package)
# ensure_pkg('pyftpdlib')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment