forked from sunfounder/vilib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.py
More file actions
163 lines (143 loc) · 4.29 KB
/
install.py
File metadata and controls
163 lines (143 loc) · 4.29 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python3
import os, sys
errors = []
avaiable_options = ['-h', '--help', '--no-dep']
usage = '''
Usage:
sudo python3 install.py [option]
Options:
--no-dep Do not download dependencies
-h --help Show this help text and exit
'''
APT_INSTALL_LIST = [
# Python3 package management tool
# "python3-pip", #
# "python3-setuptools",
# install compilation tools
"cmake",
"gcc",
"g++",
# install numpy
"python3-numpy",
# GTK support for GUI features, Camera support (v4l), Media Support (ffmpeg, gstreamer) etc
# https://docs.opencv.org/4.x/d2/de6/tutorial_py_setup_in_ubuntu.html
"libavcodec-dev",
"libavformat-dev ",
"libswscale-dev",
"libgstreamer-plugins-base1.0-dev",
"libgstreamer1.0-dev",
"libgtk2.0-dev",
"libgtk-3-dev",
# update image format support library
"libpng-dev",
"libjpeg-dev",
"libopenexr-dev",
"libtiff-dev",
"libwebp-dev",
# install python3-opencv
"python3-opencv",
# install python3-picamera
"python3-picamera",
# install mediapipe-rpi3 dependency
"ffmpeg",
"libgtk-3-0",
"libxcb-shm0",
"libcdio-paranoia-dev",
"libsdl2-2.0-0",
"libxv1",
"libtheora0",
"libva-drm2",
"libva-x11-2",
"libvdpau1",
"libharfbuzz0b",
"libbluray2",
"libatlas-base-dev",
"libhdf5-103",
"libdc1394-22",
"libopenexr23",
# pyzbar:one-dimensional barcodes and QR codes
"libzbar0",
]
PIP_INSTALL_LIST = [
"Flask",
"imutils",
"mediapipe-rpi3",
# install tflite_runtime
# "https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_armv7l.whl"
"./tflite_runtime-2.1.0.post1-cp37-cp37m-linux_armv7l.whl",
# "face-recognition",
# pyzbar:one-dimensional barcodes and QR codes
"pyzbar",
"pyzbar[scripts]",
]
def install():
options = []
if len(sys.argv) > 1:
options = sys.argv[1:]
for o in options:
if o not in avaiable_options:
print("Option {} is not found.".format(o))
print(usage)
quit()
if "-h" in options or "--help" in options:
print(usage)
quit()
print("vilib install process starts")
if "--no-dep" not in options:
do(msg="update apt",
cmd='sudo apt update -y')
# do(msg="upgrade apt",
# cmd='sudo apt upgrade -y')
print("Install dependency")
for dep in APT_INSTALL_LIST:
do(msg="install %s"%dep,
cmd='sudo apt install %s -y'%dep)
for dep in PIP_INSTALL_LIST:
do(msg="install %s"%dep,
cmd='sudo pip3 install %s'%dep)
print("Create workspace")
if not os.path.exists('/opt'):
os.mkdir('/opt')
os.popen('sudo chmod 774 /opt')
do(msg="create dir",
cmd='sudo mkdir -pf /opt/vilib')
do(msg="copy workspace",
cmd='sudo cp -r ./workspace/* /opt/vilib/')
do(msg="add write permission to log file",
cmd='sudo touch /opt/vilib/log && sudo chmod 774 /opt/vilib/log')
print("Install vilib python package")
do(msg="run setup file",
cmd='sudo python3 setup.py install')
do(msg="cleanup",
cmd='sudo rm -rf vilib.egg-info')
# check errors
if len(errors) == 0:
print("Finished")
else:
print("\n\nError happened in install process:")
for error in errors:
print(error)
print("Try to fix it yourself, or contact service@sunfounder.com with this message")
sys.exit(1)
def run_command(cmd=""):
import subprocess
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = p.stdout.read().decode('utf-8')
status = p.poll()
return status, result
def do(msg="", cmd=""):
print(" - %s... " % (msg), end='', flush=True)
status, result = run_command(cmd)
# print(status, result)
if status == 0 or status == None or result == "":
print('Done')
else:
print('Error')
errors.append("%s error:\n Status:%s\n Error:%s" %
(msg, status, result))
if __name__ == "__main__":
try:
install()
except KeyboardInterrupt:
print("Canceled.")