Skip to content

Commit ba52be0

Browse files
authored
Build python3.6 from source (#748)
* Build python3 from source * path change * Update Dockerfile * Fix python install path * More sane init-actions.sh * Add ldconfig
1 parent 6e143df commit ba52be0

File tree

3 files changed

+110
-20
lines changed

3 files changed

+110
-20
lines changed

docker/jupyter/Dockerfile

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,24 @@ RUN echo "deb $DEBIAN_REPO/debian stretch main" > /etc/apt/sou
3131
lsb-release \
3232
procps \
3333
openssl \
34+
make \
35+
libssl-dev \
36+
zlib1g-dev \
37+
libbz2-dev \
38+
libreadline-dev \
39+
libsqlite3-dev \
40+
llvm \
41+
libncurses5-dev \
42+
libncursesw5-dev \
43+
xz-utils \
44+
tk-dev \
3445
# to support userScript pip installs via git
3546
git \
3647
locales \
3748

3849
# R separately because it depends on gnupg installed above
3950
&& echo "deb $CRAN_REPO/bin/linux/debian stretch-cran35/" >> /etc/apt/sources.list \
40-
&& apt-key adv --no-tty --keyserver keys.gnupg.net \
51+
&& apt-key adv --no-tty --keyserver keyserver.ubuntu.com \
4152
--recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF' \
4253

4354
# Uncomment en_US.UTF-8 for inclusion in generation
@@ -61,9 +72,9 @@ ENV LC_ALL en_US.UTF-8
6172
# Java
6273
#######################
6374

64-
ENV JAVA_VER jdk1.8.0_191
65-
ENV JAVA_TGZ jdk-8u191-linux-x64.tar.gz
66-
ENV JAVA_URL http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/$JAVA_TGZ
75+
ENV JAVA_VER jdk1.8.0_201
76+
ENV JAVA_TGZ jdk-8u201-linux-x64.tar.gz
77+
ENV JAVA_URL https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/$JAVA_TGZ
6778
ENV JAVA_HOME /usr/lib/jdk/$JAVA_VER
6879

6980
RUN wget --header "Cookie: oraclelicense=accept-securebackup-cookie" $JAVA_URL \
@@ -130,7 +141,7 @@ RUN apt-get update \
130141

131142
# NOTE! not sure why, but this must run before pip installation
132143
&& useradd -m -s /bin/bash -N -u $UID $USER \
133-
# jessie's default pip doesn't work well with jupyter
144+
# jessie's default pip doesn't work well with jupyter
134145
&& wget -nv https://bootstrap.pypa.io/get-pip.py \
135146
&& python get-pip.py \
136147
&& pip install ipykernel==4.10.0 \
@@ -166,16 +177,79 @@ RUN apt-get update \
166177

167178

168179
# Python 3 Kernel
180+
ENV PYTHON_VERSION 3.6.8
181+
182+
# lifted from https://github.com/docker-library/python/blob/dd36c08c1f94083476a8579b8bf20c4cd46c6400/3.6/stretch/Dockerfile
183+
RUN set -ex \
184+
\
185+
&& wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \
186+
&& wget -O python.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \
187+
&& export GNUPGHOME="$(mktemp -d)" \
188+
&& gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D" \
189+
&& gpg --batch --verify python.tar.xz.asc python.tar.xz \
190+
&& { command -v gpgconf > /dev/null && gpgconf --kill all || :; } \
191+
&& rm -rf "$GNUPGHOME" python.tar.xz.asc \
192+
&& mkdir -p /usr/src/python \
193+
&& tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz \
194+
&& rm python.tar.xz \
195+
\
196+
&& cd /usr/src/python \
197+
&& gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)" \
198+
&& ./configure \
199+
--build="$gnuArch" \
200+
--enable-loadable-sqlite-extensions \
201+
--enable-shared \
202+
--with-system-expat \
203+
--with-system-ffi \
204+
--without-ensurepip \
205+
&& make -j "$(nproc)" \
206+
&& make install \
207+
&& ldconfig \
208+
\
209+
&& find /usr/local -depth \
210+
\( \
211+
\( -type d -a \( -name test -o -name tests \) \) \
212+
-o \
213+
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
214+
\) -exec rm -rf '{}' + \
215+
&& rm -rf /usr/src/python \
216+
\
217+
&& python3 --version
218+
219+
# make some useful symlinks that are expected to exist
220+
RUN cd /usr/local/bin \
221+
&& ln -s idle3 idle \
222+
&& ln -s pydoc3 pydoc \
223+
&& ln -s python3 python \
224+
&& ln -s python3-config python-config
225+
226+
# if this is called "PIP_VERSION", pip explodes with "ValueError: invalid truth value '<VERSION>'"
227+
ENV PYTHON_PIP_VERSION 19.0.1
228+
229+
RUN set -ex; \
230+
\
231+
wget -O get-pip.py 'https://bootstrap.pypa.io/get-pip.py'; \
232+
\
233+
python get-pip.py \
234+
--disable-pip-version-check \
235+
--no-cache-dir \
236+
"pip==$PYTHON_PIP_VERSION" \
237+
; \
238+
pip --version; \
239+
\
240+
find /usr/local -depth \
241+
\( \
242+
\( -type d -a \( -name test -o -name tests \) \) \
243+
-o \
244+
\( -type f -a \( -name '*.pyc' -o -name '*.pyo' \) \) \
245+
\) -exec rm -rf '{}' +; \
246+
rm -f get-pip.py
247+
169248
RUN apt-get update \
170249
&& apt-get install -t testing -yq --no-install-recommends \
171-
python3.6 \
172-
python3.6-dev \
173-
python3-distutils \
174250
# for jupyterlab extensions
175251
nodejs \
176252
npm \
177-
&& update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 100 \
178-
&& python3 get-pip.py \
179253
&& pip3 install tornado==4.5.3 \
180254
# # Hail requires decorator
181255
&& pip3 install -U decorator==4.3.0 \
@@ -215,7 +289,7 @@ RUN apt-get update \
215289
&& rm -rf /var/lib/apt/lists/*
216290

217291
# fixed current ggplot issue where it imports Timestamp from pandas.lib (deprecated) instead of pandas
218-
RUN sed -i 's/pandas.lib/pandas/g' /usr/local/lib/python3.6/dist-packages/ggplot/stats/smoothers.py
292+
RUN sed -i 's/pandas.lib/pandas/g' /usr/local/lib/python3.6/site-packages/ggplot/stats/smoothers.py
219293

220294
# make pip install to a user directory, instead of a system directory which requires root.
221295
# this is useful so `pip install` commands can be run in the context of a notebook.
@@ -281,4 +355,4 @@ USER $USER
281355
WORKDIR $HOME
282356

283357
EXPOSE $JUPYTER_PORT
284-
ENTRYPOINT ["/usr/local/bin/jupyter", "notebook"]
358+
ENTRYPOINT ["/usr/local/bin/jupyter", "notebook"]

docker/jupyter/scripts/run-jupyter.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
set -e
44

5-
# Forces python 2
6-
JUPYTER_BASE="/usr/bin/python3 /usr/local/bin/jupyter-notebook"
5+
# Forces python 3
6+
JUPYTER_BASE="/usr/local/bin/python3 /usr/local/bin/jupyter-notebook"
77
JUPYTER_CMD="$JUPYTER_BASE --NotebookApp.nbserver_extensions=\"{'jupyter_localize_extension':True}\" &> ${HOME}/jupyter.log"
88

99
echo $JUPYTER_CMD

src/main/resources/jupyter/init-actions.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,25 @@ if [[ "${ROLE}" == 'Master' ]]; then
313313
log 'All done!'
314314
fi
315315

316-
export DEBIAN_FRONTEND=noninteractive
317-
echo "deb http://ftp.de.debian.org/debian testing main" >> /etc/apt/sources.list
318-
retry 5 betterAptGet
319-
retry 5 apt-get -yq --force-yes install -t testing --no-install-recommends \
320-
python3.6
321-
retry 5 update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 100
316+
# Install Python 3.6 on the master and worker VMs
317+
export PYTHON_VERSION=3.6.8
318+
log "Installing Python $PYTHON_VERSION on the VM..."
319+
wget -O python.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz"
320+
mkdir -p /usr/src/python
321+
tar -xJC /usr/src/python --strip-components=1 -f python.tar.xz
322+
rm python.tar.xz
323+
cd /usr/src/python
324+
gnuArch="$(dpkg-architecture --query DEB_BUILD_GNU_TYPE)"
325+
./configure \
326+
--build="$gnuArch" \
327+
--enable-loadable-sqlite-extensions \
328+
--enable-shared \
329+
--with-system-expat \
330+
--with-system-ffi \
331+
--without-ensurepip
332+
make -j "$(nproc)"
333+
make install
334+
ldconfig
335+
python3 --version
336+
337+
log "Finished installing Python $PYTHON_VERSION"

0 commit comments

Comments
 (0)