-
Notifications
You must be signed in to change notification settings - Fork 401
/
checkenv.py
64 lines (49 loc) · 1.62 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
52
53
54
55
56
57
58
59
60
61
62
63
64
# Check that the packages are installed.
import sys
from pkgutil import iter_modules
import subprocess
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)
# Credit: @bill-tucker-zywave for suggesting this fix.
# https://github.com/ericmjl/Network-Analysis-Made-Simple/issues/286#issuecomment-1108793656
result = subprocess.run("ffmpeg -version", shell=True)
assert (
result.returncode == 0
), "please install ffmpeg and ensure that it is on your PATH."
# Credit: @zmilicc for requesting this.
print("All checks passed. Your environment is good to go!")