Skip to content

Instantly share code, notes, and snippets.

@rhoconlinux
Created January 17, 2024 10:09
Show Gist options
  • Save rhoconlinux/681bf042541d7c8e59bafc26139b4e13 to your computer and use it in GitHub Desktop.
Save rhoconlinux/681bf042541d7c8e59bafc26139b4e13 to your computer and use it in GitHub Desktop.
pip_check_then_install.py
def check_and_install(package):
try:
importlib.metadata.version(package)
print(f"Package {package} already installed ... ✅")
except importlib.metadata.PackageNotFoundError:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', package])
#use:
#check_and_install("langchain")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment