Last active
April 1, 2020 18:02
-
-
Save Pr1meSuspec7/07a085089f46300af37de640f9e40d72 to your computer and use it in GitHub Desktop.
Fucntion to check and install missing packages
This file contains hidden or 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
| import re | |
| import sys | |
| import subprocess | |
| def pkg_requirement(*pkgs): | |
| output = subprocess.check_output((['pip', 'list'])) | |
| outputDecode = output.decode("utf-8") | |
| #print(outputDecode) | |
| pipList = re.split(r'\s', outputDecode) | |
| pipNeed = [] | |
| for pkg in pkgs: | |
| if not pkg in pipList: | |
| print(pkg + ' not installed') | |
| pipNeed.append(pkg) | |
| else: | |
| print(pkg + ' already installed') | |
| #print(pipNeed) | |
| for pkg in pipNeed: | |
| subprocess.call([sys.executable, "-m", "pip", "install", pkg]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment