Skip to content

Instantly share code, notes, and snippets.

@Pr1meSuspec7
Last active April 1, 2020 18:02
Show Gist options
  • Select an option

  • Save Pr1meSuspec7/07a085089f46300af37de640f9e40d72 to your computer and use it in GitHub Desktop.

Select an option

Save Pr1meSuspec7/07a085089f46300af37de640f9e40d72 to your computer and use it in GitHub Desktop.
Fucntion to check and install missing packages
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