Created
December 21, 2016 01:57
-
-
Save tamalsaha/d507005f4a55a0487d7f9b4693146d18 to your computer and use it in GitHub Desktop.
Check if a python module is installed
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
# http://stackoverflow.com/a/14050282 | |
def check_antipackage(): | |
from sys import version_info | |
sys_version = version_info[:2] | |
found = True | |
if sys_version < (3, 0): | |
# 'python 2' | |
from pkgutil import find_loader | |
found = find_loader('antipackage') is not None | |
elif sys_version <= (3, 3): | |
# 'python <= 3.3' | |
from importlib import find_loader | |
found = find_loader('antipackage') is not None | |
else: | |
# 'python >= 3.4' | |
from importlib import util | |
found = util.find_spec('antipackage') is not None | |
if not found: | |
print('Install missing package "antipackage"') | |
print('Example: pip install git+https://github.com/ellisonbg/antipackage.git#egg=antipackage') | |
from sys import exit | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment