33import sys , os , subprocess
44import argparse
55import re
6+ import platform
67
78convert_default = "empty"
89parser = argparse .ArgumentParser ()
@@ -38,7 +39,21 @@ def hasWhitespace(string):
3839import find_version
3940
4041# 3rdparty dependencies to install
41- DEPENDENCIES = ['numpy' , 'opencv-python' , 'pyyaml' , 'requests' ]
42+ DEPENDENCIES = ['pyyaml' , 'requests' ]
43+ requireOpenCv = True
44+ thisPlatform = platform .machine ()
45+ if thisPlatform == "aarch64" :
46+ # try to import opencv, numpy in a subprocess, since it might fail with illegal instruction
47+ # if it was previously installed w/ pip without setting OPENBLAS_CORE_TYPE=ARMV8 env variable
48+ try :
49+ subprocess .check_call ([sys .executable , "-c" , "import numpy, cv2;" ])
50+ requireOpenCv = False
51+ except subprocess .CalledProcessError as ex :
52+ requireOpenCv = True
53+
54+ if requireOpenCv :
55+ DEPENDENCIES .append ('opencv-python' )
56+
4257
4358# Constants
4459ARTIFACTORY_URL = 'https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local'
@@ -61,12 +76,13 @@ def hasWhitespace(string):
6176if sys .version_info [0 ] != 3 :
6277 raise RuntimeError ("Examples require Python 3 to run (detected: Python {})" .format (sys .version_info [0 ]))
6378
64- if platform . machine () == "arm64" and platform .system () == "Darwin" :
79+ if thisPlatform == "arm64" and platform .system () == "Darwin" :
6580 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"
6681 raise RuntimeError (err_str )
6782
68- is_pi = platform .machine ().startswith ("arm" ) or platform .machine ().startswith ("aarch" )
69- if is_pi and sys .version_info [1 ] == 9 :
83+ is_pi = thisPlatform .startswith ("arm" )
84+ prebuiltWheelsPythonVersion = [7 ,9 ]
85+ if requireOpenCv and is_pi and sys .version_info [1 ] not in prebuiltWheelsPythonVersion :
7086 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 ]))
7187
7288if not in_venv :
@@ -158,3 +174,14 @@ def hasWhitespace(string):
158174 prettyPrint (cmd )
159175 else :
160176 subprocess .check_call (cmd )
177+
178+ if requireOpenCv and thisPlatform == "aarch64" :
179+ from os import environ
180+ OPENBLAS_CORE_TYPE = environ .get ('OPENBLAS_CORE_TYPE' )
181+ if OPENBLAS_CORE_TYPE != 'ARMV8' :
182+ WARNING = '\033 [1;5;31m'
183+ RED = '\033 [91m'
184+ LINE_CL = '\033 [0m'
185+ SUGGESTION = 'echo "export OPENBLAS_CORETYPE=AMRV8" >> ~/.bashrc && source ~/.bashrc'
186+ print (f'{ WARNING } WARNING:{ LINE_CL } Need to set OPENBLAS_CORE_TYPE environment variable, otherwise opencv will fail with illegal instruction.' )
187+ print (f'Run: { RED } { SUGGESTION } { LINE_CL } ' )
0 commit comments