Skip to content

Commit ca2a361

Browse files
authored
Guided Pyhton venv install for macOS and Linux
Derived from PR oscarpilote#248
1 parent 3a75362 commit ca2a361

File tree

1 file changed

+121
-24
lines changed

1 file changed

+121
-24
lines changed

z_Install_O4XP_Python_Venv.sh

Lines changed: 121 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#! /bin/bash
22

3+
py_ver="3.12"
4+
35
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
46

57
venv_path=$SCRIPT_DIR/venv-ortho
68

79
if [ ! -f "$SCRIPT_DIR/Ortho4XP.py" ]; then
810
echo " "
9-
echo "Error: file Ortho4XP.py not found!"
11+
echo "Error !"
1012
echo " "
11-
echo "Place z_Install_O4XP_Python3.12_Venv.sh in the main O4XP direcory !"
13+
echo "Place z_Install_O4XP_Python_Venv.sh in the main O4XP direcory !"
1214
echo " "
1315
exit 1
1416
fi
@@ -47,9 +49,12 @@ package_exists(){
4749
fi
4850
}
4951

50-
package_exists python@3.12
52+
if ! [ -x "$(command -v python$py_ver)" ]; then
53+
echo "Python $py_ver not found! Installing ..."
54+
brew install python@$py_ver
55+
fi
5156

52-
if [[ "$(which python3.12)" != *"homebrew"* ]]; then
57+
if [[ "$(which python$py_ver)" != *"homebrew"* ]]; then
5358
echo " "
5459
echo "Python installed via Homebrew is required !"
5560
echo "Remove the PATH for Python in the hidden file .zprofile in your user directory !"
@@ -64,28 +69,124 @@ package_exists python@3.12
6469
echo " "
6570
exit 1
6671
fi
67-
package_exists gdal
68-
package_exists python-tk@3.12
72+
73+
if ! [ -x "$(command -v gdalwarp)" ]; then
74+
echo "GDAL not found! Installing..."
75+
brew install gdal
76+
fi
77+
78+
if ! [ -x "$(command -v 7z)" ]; then
79+
echo "p7zip not found! Installing..."
80+
brew install p7zip
81+
fi
82+
83+
package_exists python-tk@$py_ver
6984
package_exists proj
7085
package_exists spatialindex
71-
package_exists p7zip
86+
87+
# Semi-automated, guided installation for Linux
7288

7389
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
74-
echo "LINUX"
75-
76-
if ! [ -x "$(command -v python3.12)" ]; then
77-
echo " "
78-
echo "Python 3.12 is not installed. Aborting! "
79-
echo " "
80-
exit 1
90+
91+
92+
if type lsb_release >/dev/null 2>&1; then
93+
# linuxbase.org
94+
OS=$(lsb_release -si)
95+
VER=$(lsb_release -sr)
96+
elif [ -f /etc/lsb-release ]; then
97+
# For some versions of Debian/Ubuntu without lsb_release command
98+
. /etc/lsb-release
99+
OS=$DISTRIB_ID
100+
VER=$DISTRIB_RELEASE
101+
elif [ -f /etc/debian_version ]; then
102+
# Older Debian/Ubuntu/etc.
103+
OS=Debian
104+
VER=$(cat /etc/debian_version)
105+
106+
fi
107+
108+
echo "Linux $OS"
109+
echo "Version: $VER"
110+
111+
112+
Ubuntu24="apt-get install python3 python3-pip python3-venv python3-gdal python3-pil.imagetk p7zip-full libnvtt-bin freeglut3-dev gdal-bin"
113+
Debian="apt install python3 python3-venv python3-pip python3-gdal python3-pil.imagetk p7zip-full libnvtt-bin freeglut3 gdal-bin"
114+
Arch="pacman -S python python-pip python-gdal p7zip freeglut tk podofo netcdf mariadb hdf5 cfitsio postgresql"
115+
116+
117+
if [[ "$OS" == *"Ubuntu"* ]]; then
118+
py_ver="3"
119+
if [[ "$VER" == *"24"* ]]; then
120+
system_packages=$Ubuntu24
121+
else
122+
system_packages=$Debian
81123
fi
82-
if ! [ -x "$(command -v gdalwarp)" ]; then
124+
125+
elif [[ "$OS" == *"Mint"* ]]; then
126+
py_ver="3"
127+
system_packages=$Debian
128+
129+
elif [[ "$OS" == *"Debian"* ]]; then
130+
py_ver="3"
131+
system_packages=$Debian
132+
elif [[ "$OS" == *"Arch"* ]]; then
133+
system_packages=$Arch
134+
elif [[ "$OS" == *"Manjaro"* ]]; then
135+
system_packages=$Arch
136+
else
137+
OS="Unknown"
138+
fi
139+
140+
141+
if ! [ -x "$(command -v gdalwarp)" ]; then
83142
echo " "
84-
echo "Install system packages required by Ortho4XP as per included Install_Instructions.txt!"
143+
echo "It looks like system packages required by Ortho4XP are not installed!"
85144
echo " "
86-
exit 1
87-
fi
145+
fi
146+
147+
148+
if [[ "$OS" == "Unknown" ]]; then
149+
echo " "
150+
echo "Do you want to install system packages required by Ortho4XP ?"
151+
read -p "Install for distribution based on Arch? (a) Debian? (d) Skip installation? (s) " ads
152+
echo " "
153+
case $ads in
154+
s ) echo ok, we will proceed without installation of system packages;;
155+
a ) echo Installing system packages for Arch-based distribution ;
156+
py_ver="3.12";
157+
sudo $Arch;;
158+
d ) echo Installing system packages for Debian-based distribution ;
159+
py_ver="3";
160+
sudo $Debian;;
161+
* ) echo invalid response;
162+
exit 1;;
163+
esac
164+
165+
166+
else
167+
168+
read -p "Do you want to install system packages for $OS required by Ortho4XP? (y/n) " yn
169+
170+
case $yn in
171+
n ) echo ok, we will proceed without installation of system packages;;
172+
y ) echo Installing system packages ;
173+
sudo $system_packages;;
174+
* ) echo invalid response;
175+
exit 1;;
176+
esac
88177

178+
fi
179+
180+
echo " "
181+
182+
if ! [ -x "$(command -v python$py_ver)" ]; then
183+
if [ -x "$(command -v python)" ]; then
184+
py_ver=""
185+
else
186+
py_ver="3"
187+
fi
188+
fi
189+
89190
else
90191
echo "Unsupported system!"
91192
exit 1
@@ -98,9 +199,9 @@ if [ -d $venv_path ]; then
98199
rm -rf $venv_path
99200
fi
100201

101-
# Create a Python 3.12 virtual environment
202+
# Create a Python virtual environment
102203

103-
python3.12 -m venv --system-site-packages $venv_path
204+
python$py_ver -m venv --system-site-packages $venv_path
104205

105206
# Activate Python venv
106207

@@ -112,8 +213,6 @@ cd $SCRIPT_DIR
112213

113214
pip install -I -r requirements.txt
114215

115-
# DONE
116-
117216
echo " "
118217

119218
if [ -d "$venv_path/bin" ]; then
@@ -124,8 +223,6 @@ echo " "
124223
echo "Installed packages:"
125224
pip list
126225
echo " "
127-
echo "GDAL version: $(gdal-config --version)"
128-
echo " "
129226
echo " "
130227
echo "Use $SCRIPT_DIR/z_Start_O4XP_PythonVenv.sh to start O4XP"
131228
echo " "

0 commit comments

Comments
 (0)