Skip to content

Commit 13f3d68

Browse files
Merge pull request #322 from luxonis/arm64_dependency_fix
Fix dependencies for arm64
2 parents c7bea3f + e2ed466 commit 13f3d68

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

examples/install_requirements.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys, os, subprocess
44
import argparse
55
import re
6+
import platform
67

78
convert_default = "empty"
89
parser = argparse.ArgumentParser()
@@ -38,7 +39,21 @@ def hasWhitespace(string):
3839
import 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
4459
ARTIFACTORY_URL = 'https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local'
@@ -61,12 +76,13 @@ def hasWhitespace(string):
6176
if 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

7288
if 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

Comments
 (0)