forked from ericmjl/Network-Analysis-Made-Simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckenv.py
51 lines (35 loc) · 1.4 KB
/
checkenv.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
41
42
43
44
45
46
47
48
49
50
51
# Check that the packages are installed.
from pkgutil import iter_modules
import sys
import os
def check_import(packagename):
if packagename in (name for _, name, _ in iter_modules()):
return True
else:
return False
# If there are new packages that you can import, add them to the list.
package_names = ['networkx', 'numpy', 'matplotlib', 'hiveplot', 'pandas',
'jupyter', 'nxviz', 'tqdm']
packages = {n: n for n in package_names}
# Only add the packages whose import names are different from the
# package name (what we `pip install` or `conda install`).
packages['community'] = 'python-louvain'
assert (sys.version_info.major >= 3 and sys.version_info.minor >= 6), 'Please install Python 3.6!'
def print_error(p, i):
"""
Returns the error message for package installation issues.
:param str p: The name of the package to install.
:param str i: The name of the package when imported.
"""
error_message = f"""
{i} not present. Please do the installation using either:
- pip install {p}
- conda install -c conda-forge {p}
"""
return error_message
for p, i in packages.items():
assert check_import(p), print_error(i, p)
# os.system returns 0 if command passed
assert not os.system('command -v ffmpeg'), "please install ffmpeg"
# Credit: @zmilicc for requesting this.
print('All checks passed. Your environment is good to go!')