Created
January 17, 2024 10:09
-
-
Save rhoconlinux/681bf042541d7c8e59bafc26139b4e13 to your computer and use it in GitHub Desktop.
pip_check_then_install.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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