-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_python_installation.py
40 lines (30 loc) · 1.31 KB
/
check_python_installation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Author: Hugo Bowne-Anderson original from Data Carpentry
# https://github.com/datacarpentry/python-ecology-lesson/blob/gh-pages/_includes/scripts/check_env.py
import sys
from pkgutil import iter_modules
# Thanks @ericmjl for function below.
def check_import(packagename):
"""Checks whether a package is installed"""
if packagename in (name for _, name, _ in iter_modules()):
return True
else:
return False
all_checks_passed = True
# Throw error if Anaconda is not default Python
assert 'anaconda' in sys.prefix, ("Anaconda is NOT installed as your "
"default version of Python. Please "
"make sure that is in accordance "
"with the instructions provided.")
# Throw error if Python 2 is not default Python
assert sys.version_info.major >= 2, 'Please install Python 3!'
# Packages necessary for workshop
packages = ['numpy', 'matplotlib', 'pandas', 'jupyter']
# Throw error if any of the necessary packages is not installed
for p in packages:
assert check_import(p),\
("{0} not present. You may have installed a subset of the"
"required distribution. Please install the entire Anaconda"
"distribution").format(p)
if all_checks_passed:
print("All checks passed. Your Anaconda installation is up and "
"running and ready for you!")