Skip to content

Instantly share code, notes, and snippets.

@dkdndes
Created February 24, 2019 13:24
Show Gist options
  • Select an option

  • Save dkdndes/673950b62a8dd50a229d0f9c94ef6d11 to your computer and use it in GitHub Desktop.

Select an option

Save dkdndes/673950b62a8dd50a229d0f9c94ef6d11 to your computer and use it in GitHub Desktop.
"""This file checks, if the package is installed on the current system."""
import os
import sys
import argparse
from importlib import import_module
def main():
"""
Check if the package name is installed.
Returns true, if the package is installed, otherwise false.
"""
try:
# Parse the argument as project name
desc_string = "Check if the python package is installed."
parser = argparse.ArgumentParser(description=desc_string)
parser.add_argument('package_name', action="store", type=str)
package_name = parser.parse_args().package_name
import_module(package_name)
print('true')
except ImportError:
print('false')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment