Skip to content

Commit c5b7d0a

Browse files
authored
Check install (openvinotoolkit#197)
* Update check_install.py script and add test * Add venv * check_output fix * pythonpath * add python * env python * env * linux specific * path * venv * Update check install test * Fix nbval rebase issue
1 parent deaa959 commit c5b7d0a

File tree

2 files changed

+95
-48
lines changed

2 files changed

+95
-48
lines changed

.github/workflows/nbval.yml

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
with:
4242
name: pip-freeze
4343
path: pip-freeze-${{ github.sha }}-${{matrix.os}}-${{ matrix.python }}.txt
44+
- name: Check install
45+
run: |
46+
python check_install.py
4447
- name: Check READMEs
4548
run: |
4649
python -m pytest .ci/test_notebooks.py

check_install.py

+92-48
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,72 @@
11
import os
2+
import subprocess
23
import sys
34
from pprint import pprint
45

6+
import pip
7+
8+
try:
9+
from jupyter_client.kernelspec import KernelSpecManager, NoSuchKernel
10+
except:
11+
print(
12+
"Importing Jupyter failed. Please follow the installation instructions "
13+
"in the README in the same directory as this script or "
14+
"at https://github.com/openvinotoolkit/openvino_notebooks."
15+
)
16+
sys.exit()
17+
18+
19+
20+
def show_supported(supported):
21+
"""
22+
Returns OK (in green) if supported evaluates to True, otherwise NOT OK (in red).
23+
"""
24+
try:
25+
from colorama import Fore, Style, init
26+
27+
init()
28+
startcolor = Fore.GREEN if supported else Fore.RED
29+
stopcolor = Style.RESET_ALL
30+
except:
31+
startcolor = stopcolor = ""
32+
output = "OK" if supported else "NOT OK"
33+
return f"{startcolor}{output}{stopcolor}"
34+
35+
36+
def pip_check():
37+
result = subprocess.check_output(["pip", "check"], universal_newlines=True)
38+
if "No broken requirements found" in result:
39+
return True, ""
40+
else:
41+
return False, result
42+
43+
44+
def kernel_check():
45+
try:
46+
kernel = KernelSpecManager().get_kernel_spec("openvino_env")
47+
except NoSuchKernel:
48+
return False, ""
49+
kernel_python = kernel.argv[0]
50+
return True, kernel_python
51+
52+
553
PYTHON_EXECUTABLE = sys.executable
654
PYTHON_VERSION = sys.version_info
55+
PIP_VERSION = pip.__version__
756
OS = sys.platform
57+
KERNEL_INSTALLED, KERNEL_PYTHON = kernel_check()
58+
NO_BROKEN_REQUIREMENTS, PIP_CHECK_OUTPUT = pip_check()
59+
60+
CORRECT_KERNEL_PYTHON = PYTHON_EXECUTABLE == KERNEL_PYTHON
861

962
IN_OPENVINO_ENV = "openvino_env" in sys.executable
1063
SUPPORTED_PYTHON_VERSION = PYTHON_VERSION.major == 3 and (
1164
PYTHON_VERSION.minor >= 6 and PYTHON_VERSION.minor <= 8
1265
)
13-
GLOBAL_OPENVINO_INSTALLED = "openvino_202" in os.environ.get(
14-
"LD_LIBRARY_PATH", ""
15-
) + ":".join(sys.path)
66+
GLOBAL_OPENVINO_INSTALLED = "openvino_202" in os.environ.get("LD_LIBRARY_PATH", "") + ":".join(
67+
sys.path
68+
)
69+
1670

1771
try:
1872
import openvino
@@ -30,67 +84,47 @@
3084

3185
try:
3286
import mo_onnx
33-
import numpy
34-
35-
NUMPY_VERSION = numpy.__version__
36-
SUPPORTED_NUMPY_VERSION = NUMPY_VERSION < "1.19"
3787
except ImportError:
3888
DEVTOOLS_INSTALLED = False
3989
else:
4090
DEVTOOLS_INSTALLED = True
4191

4292

43-
def show_supported(supported):
44-
"""
45-
Returns OK (in green) if supported evaluates to True, otherwise NOT OK (in red).
46-
"""
47-
try:
48-
from colorama import Fore, Back, Style
49-
from colorama import init
50-
51-
init()
52-
startcolor = Fore.GREEN if supported else Fore.RED
53-
stopcolor = Style.RESET_ALL
54-
except:
55-
startcolor = stopcolor = ""
56-
output = "OK" if supported else "NOT OK"
57-
return f"{startcolor}{output}{stopcolor}"
58-
59-
6093
print("System information:")
6194
print(f"Python executable: {PYTHON_EXECUTABLE}")
95+
96+
print(f"Pip version: {PIP_VERSION}")
6297
print(f"OpenVINO environment activated: {show_supported(IN_OPENVINO_ENV)}")
98+
print(f"Jupyter kernel installed for openvino_env: {show_supported(KERNEL_INSTALLED)}")
99+
if KERNEL_INSTALLED:
100+
print(f"Jupyter kernel Python executable: {KERNEL_PYTHON}")
101+
print(
102+
"Jupyter kernel Python and OpenVINO environment Python match: "
103+
f"{show_supported(CORRECT_KERNEL_PYTHON)}"
104+
)
63105
print(
64106
f"Python version: {PYTHON_VERSION.major}.{PYTHON_VERSION.minor} "
65107
f"{show_supported(SUPPORTED_PYTHON_VERSION)}"
66108
)
67-
print(
68-
f"OpenVINO pip package installed: {show_supported(PIP_OPENVINO_INSTALLED)}"
69-
)
109+
print(f"OpenVINO pip package installed: {show_supported(PIP_OPENVINO_INSTALLED)}")
70110
print(f"OpenVINO import succeeds: {show_supported(OPENVINO_IMPORT)}")
71-
print(
72-
f"OpenVINO development tools installed: {show_supported(DEVTOOLS_INSTALLED)}"
73-
)
74-
print(
75-
f"OpenVINO not installed globally: {show_supported(not GLOBAL_OPENVINO_INSTALLED)}"
76-
)
77-
if DEVTOOLS_INSTALLED:
78-
print(
79-
f"Numpy version: {NUMPY_VERSION} {show_supported(SUPPORTED_NUMPY_VERSION)}"
80-
)
111+
print(f"OpenVINO development tools installed: {show_supported(DEVTOOLS_INSTALLED)}")
112+
print(f"OpenVINO not installed globally: {show_supported(not GLOBAL_OPENVINO_INSTALLED)}")
113+
114+
print(f"No broken requirements: {show_supported(NO_BROKEN_REQUIREMENTS)}")
81115
print()
82116

83117
if not PIP_OPENVINO_INSTALLED:
84118
print(
85-
f"The OpenVINO PIP package is not installed in this environment. Please\n"
119+
"The OpenVINO PIP package is not installed in this environment. Please\n"
86120
"follow the README in the same directory as this check_install script or\n"
87121
"at https://github.com/openvinotoolkit/openvino_notebooks to install OpenVINO."
88122
)
89123
sys.exit(0)
90124

91125
if not OPENVINO_IMPORT and OS != "win32" and not GLOBAL_OPENVINO_INSTALLED:
92126
print(
93-
f"OpenVINO is installed, but importing fails. This is likely due to a missing\n"
127+
"OpenVINO is installed, but importing fails. This is likely due to a missing\n"
94128
"libpython.so library for the Python version you are using.\n"
95129
)
96130
if OS == "linux":
@@ -112,6 +146,11 @@ def show_supported(supported):
112146
"environment, but if you run into trouble, please follow the instructions \n"
113147
"in the README to install and activate the `openvino_env` environment.\n"
114148
)
149+
150+
if not CORRECT_KERNEL_PYTHON:
151+
print("The Python version in openvino_env does not match the openvino_env "
152+
"Jupyter kernel. This may not be an issue. If you experience issues, please "
153+
"follow the instructions in the README to reinstall the kernel.")
115154
if GLOBAL_OPENVINO_INSTALLED:
116155
print(
117156
"It appears that you installed OpenVINO globally (for example with \n"
@@ -143,25 +182,30 @@ def show_supported(supported):
143182
"Please follow the instructions in the README to install `openvino-dev`\n"
144183
)
145184

146-
elif not SUPPORTED_NUMPY_VERSION:
147-
print(
148-
f"You have Numpy version {NUMPY_VERSION}. This may cause issues with model \n"
149-
"optimization or quantization. Please install `numpy<1.19` with \n"
150-
"`pip install numpy<1.19`. There may be errors or warnings in the output \n"
151-
"from pip because of incompatibilities. These should be harmless.\n"
152-
)
185+
if not NO_BROKEN_REQUIREMENTS:
186+
print()
187+
print("`pip check` shows broken requirements:")
188+
print(PIP_CHECK_OUTPUT)
189+
190+
print()
153191
if (
154192
IN_OPENVINO_ENV
155193
and PIP_OPENVINO_INSTALLED
156194
and OPENVINO_IMPORT
157195
and DEVTOOLS_INSTALLED
158-
and SUPPORTED_NUMPY_VERSION
159196
and SUPPORTED_PYTHON_VERSION
197+
and KERNEL_INSTALLED
198+
and CORRECT_KERNEL_PYTHON
160199
and (not GLOBAL_OPENVINO_INSTALLED)
161200
):
162-
print("Everything looks good!")
201+
if NO_BROKEN_REQUIREMENTS:
202+
print("Everything looks good!")
203+
else:
204+
print("Summary: The installation looks good, but there are conflicting requirements.")
163205
else:
164206
print(
165207
"The README.md file is located in the openvino_notebooks directory \n"
166208
"and at https://github.com/openvinotoolkit/openvino_notebooks"
167209
)
210+
if not NO_BROKEN_REQUIREMENTS:
211+
print("Broken requirements are often harmless, but could cause issues.")

0 commit comments

Comments
 (0)