From 04e83e00b8c92571feda913a72da38ac1577165f Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Fri, 23 Jul 2021 03:20:36 +0300 Subject: [PATCH 1/4] Skip opencv install on jetson --- examples/install_requirements.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/install_requirements.py b/examples/install_requirements.py index 770ec9575..e7a9299c8 100755 --- a/examples/install_requirements.py +++ b/examples/install_requirements.py @@ -2,6 +2,7 @@ import sys, os, subprocess import argparse import re +import platform parser = argparse.ArgumentParser() parser.add_argument('-sdai', "--skip_depthai", action="store_true", help="Skip installation of depthai library.") @@ -35,7 +36,12 @@ def hasWhitespace(string): import find_version # 3rdparty dependencies to install -DEPENDENCIES = ['opencv-python', 'pyyaml', 'requests'] +DEPENDENCIES = ['pyyaml', 'requests'] +if platform.machine() == "aarch64": + print('Skipping opencv install on aarch64.') +else: + DEPENDENCIES.append('opencv-python') + # Constants ARTIFACTORY_URL = 'https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local' From 8a104f01e2b24109a9355b8f305076b88508ba2f Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Wed, 13 Oct 2021 23:13:58 +0300 Subject: [PATCH 2/4] Update dependency installer for aarch64 --- examples/install_requirements.py | 33 ++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/examples/install_requirements.py b/examples/install_requirements.py index 805770433..ffbfba30c 100755 --- a/examples/install_requirements.py +++ b/examples/install_requirements.py @@ -40,9 +40,18 @@ def hasWhitespace(string): # 3rdparty dependencies to install DEPENDENCIES = ['pyyaml', 'requests'] -if platform.machine() == "aarch64": - print('Skipping opencv install on aarch64.') -else: +requireOpenCv = True +thisPlatform = platform.machine() +if thisPlatform == "aarch64": + # try to import opencv, numpy in a subprocess, since it might fail with illegal instruction + # if it was previously installed w/ pip without setting OPENBLAS_CORE_TYPE=ARMV8 env variable + try: + subprocess.check_call(["python3", "-c", "import numpy, cv2;"]) + requireOpenCv = False + except subprocess.CalledProcessError as ex: + requireOpenCv = True + +if requireOpenCv: DEPENDENCIES.append('opencv-python') @@ -67,12 +76,13 @@ def hasWhitespace(string): if sys.version_info[0] != 3: raise RuntimeError("Examples require Python 3 to run (detected: Python {})".format(sys.version_info[0])) -if platform.machine() == "arm64" and platform.system() == "Darwin": +if thisPlatform == "arm64" and platform.system() == "Darwin": err_str = "There are no prebuilt wheels for M1 processors. Please open the following link for a solution - https://discuss.luxonis.com/d/69-running-depthai-on-apple-m1-based-macs" raise RuntimeError(err_str) -is_pi = platform.machine().startswith("arm") or platform.machine().startswith("aarch") -if is_pi and sys.version_info[1] == 9: +is_pi = thisPlatform.startswith("arm") or thisPlatform.startswith("aarch") +prebuiltWheelsPythonVersion = [7,9] +if is_pi and sys.version_info[1] not in prebuiltWheelsPythonVersion: print("[WARNING] There are no prebuilt wheels for Python 3.{} for OpenCV, building process on this device may be long and unstable".format(sys.version_info[1])) if not in_venv: @@ -164,3 +174,14 @@ def hasWhitespace(string): prettyPrint(cmd) else: subprocess.check_call(cmd) + +if requireOpenCv and thisPlatform == "aarch64": + from os import environ + OPENBLAS_CORE_TYPE = environ.get('OPENBLAS_CORE_TYPE') + if OPENBLAS_CORE_TYPE != 'ARMV8': + WARNING='\033[1;5;31m' + RED='\033[91m' + LINE_CL='\033[0m' + SUGGESTION='echo "export OPENBLAS_CORETYPE=AMRV8" >> ~/.bashrc && source ~/.bashrc' + print(f'{WARNING}WARNING:{LINE_CL} Need to set OPENBLAS_CORE_TYPE environment variable, otherwise opencv will fail with illegal instruction.') + print(f'Run: {RED}{SUGGESTION}{LINE_CL}') From 7d0bd12c7731c8086ee62a335f5afc23a55accd3 Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Wed, 13 Oct 2021 23:23:18 +0300 Subject: [PATCH 3/4] Use sys.executable instead python3, improve warning message --- examples/install_requirements.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/install_requirements.py b/examples/install_requirements.py index ffbfba30c..321fb9973 100755 --- a/examples/install_requirements.py +++ b/examples/install_requirements.py @@ -46,7 +46,7 @@ def hasWhitespace(string): # try to import opencv, numpy in a subprocess, since it might fail with illegal instruction # if it was previously installed w/ pip without setting OPENBLAS_CORE_TYPE=ARMV8 env variable try: - subprocess.check_call(["python3", "-c", "import numpy, cv2;"]) + subprocess.check_call([sys.executable, "-c", "import numpy, cv2;"]) requireOpenCv = False except subprocess.CalledProcessError as ex: requireOpenCv = True @@ -82,7 +82,7 @@ def hasWhitespace(string): is_pi = thisPlatform.startswith("arm") or thisPlatform.startswith("aarch") prebuiltWheelsPythonVersion = [7,9] -if is_pi and sys.version_info[1] not in prebuiltWheelsPythonVersion: +if requireOpenCv and is_pi and sys.version_info[1] not in prebuiltWheelsPythonVersion: print("[WARNING] There are no prebuilt wheels for Python 3.{} for OpenCV, building process on this device may be long and unstable".format(sys.version_info[1])) if not in_venv: From e2ed466f5bb78f31c4cbcead7dd4ad6274c99faa Mon Sep 17 00:00:00 2001 From: SzabolcsGergely Date: Thu, 14 Oct 2021 00:38:29 +0300 Subject: [PATCH 4/4] Remove aarch64 from RPI check --- examples/install_requirements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/install_requirements.py b/examples/install_requirements.py index 321fb9973..d0f082422 100755 --- a/examples/install_requirements.py +++ b/examples/install_requirements.py @@ -80,7 +80,7 @@ def hasWhitespace(string): err_str = "There are no prebuilt wheels for M1 processors. Please open the following link for a solution - https://discuss.luxonis.com/d/69-running-depthai-on-apple-m1-based-macs" raise RuntimeError(err_str) -is_pi = thisPlatform.startswith("arm") or thisPlatform.startswith("aarch") +is_pi = thisPlatform.startswith("arm") prebuiltWheelsPythonVersion = [7,9] if requireOpenCv and is_pi and sys.version_info[1] not in prebuiltWheelsPythonVersion: print("[WARNING] There are no prebuilt wheels for Python 3.{} for OpenCV, building process on this device may be long and unstable".format(sys.version_info[1]))