forked from rocker-org/rocker-versioned2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_python.sh
executable file
·57 lines (45 loc) · 1.57 KB
/
install_python.sh
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
#!/bin/bash
set -e
## build ARGs
NCPUS=${NCPUS:--1}
# a function to install apt packages only if they are not installed
function apt_install() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
apt-get update
fi
apt-get install -y --no-install-recommends "$@"
fi
}
apt_install \
libpng-dev \
libpython3-dev \
python3-dev \
python3-pip \
python3-venv \
swig
python3 -m pip --no-cache-dir install --upgrade \
pip
# Some TF tools expect a "python" binary
if [ ! -e /usr/local/bin/python ]; then
ln -s "$(which python3)" /usr/local/bin/python
fi
install2.r --error --skipmissing --skipinstalled -n "$NCPUS" reticulate
# Clean up
rm -rf /var/lib/apt/lists/*
rm -rf /tmp/downloaded_packages
## Strip binary installed lybraries from RSPM
## https://github.com/rocker-org/rocker-versioned2/issues/340
strip /usr/local/lib/R/site-library/*/libs/*.so
## Don't use OpenBLAS with reticulate
## https://github.com/rocker-org/rocker-versioned2/issues/471
if R -q -e 'sessionInfo()' | grep -q openblas; then
ARCH=$(uname -m)
echo "Switching BLAS"
update-alternatives --set "libblas.so.3-${ARCH}-linux-gnu" "/usr/lib/${ARCH}-linux-gnu/blas/libblas.so.3"
update-alternatives --set "liblapack.so.3-${ARCH}-linux-gnu" "/usr/lib/${ARCH}-linux-gnu/lapack/liblapack.so.3"
fi
# Check Python version
echo -e "Check the Python to use with reticulate...\n"
R -q -e 'reticulate::py_discover_config(required_module = NULL, use_environment = NULL)'
echo -e "\nInstall Python, done!"