Skip to content

Commit fe0f773

Browse files
author
d1jang
authored
Merge pull request Kaggle#243 from Kaggle/pip_install_support
Patch .bashrc to set up pip to enable pip install
2 parents 5a112aa + ba2ae69 commit fe0f773

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,12 @@ ADD patches/sitecustomize.py /root/.local/lib/python3.6/site-packages/sitecustom
535535
# Set backend for matplotlib
536536
ENV MPLBACKEND "agg"
537537

538+
# Set up pip to enable pip install.
539+
ADD patches/kaggle_bashrc /root
540+
# Patch the system-wide bashrc file for non-root users.
541+
RUN cat /root/kaggle_bashrc >> /etc/bash.bashrc
542+
RUN rm /root/kaggle_bashrc
543+
538544
# Finally, apply any locally defined patches.
539545
RUN /bin/bash -c \
540546
"cd / && for p in $(ls /tmp/patches/*.patch); do echo '= Applying patch '\${p}; patch -p2 < \${p}; done"

patches/kaggle_bashrc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
# Kaggle-specific .bashrc script to be appended to /etc/bash.bashrc to apply it
3+
# when any user session starts.
4+
# This script sets up pip to enable a user to install and use python modules via
5+
# pip intall. $KAGGLE_WORKING_DIR should be available for it to work.
6+
7+
if [[ ! -z "${KAGGLE_WORKING_DIR}" ]]; then
8+
PIP_INSTALL_PREFIX_DIR="${KAGGLE_WORKING_DIR}/pip"
9+
PIP_CONFIG_FILE_PATH="${KAGGLE_WORKING_DIR}/config/pip/pip.conf"
10+
11+
# Create a directory for pip to install modules.
12+
mkdir -p ${PIP_INSTALL_PREFIX_DIR}
13+
14+
# Create pip config file to use the prefix directory created above for
15+
# installation. Also, ignore-installed is set to true to prevent pip
16+
# from trying to remove existing modules from the read-only filesystem.
17+
mkdir -p `dirname ${PIP_CONFIG_FILE_PATH}`
18+
echo "[install]\nprefix=${PIP_INSTALL_PREFIX_DIR}\nignore-installed=true" > ${PIP_CONFIG_FILE_PATH}
19+
# Instruct pip to use this config file.
20+
export PIP_CONFIG_FILE=${PIP_CONFIG_FILE_PATH}
21+
22+
# Set up PYTHONPATH correctly to include the user-installed library.
23+
# Note that the pip prefix directory overrides the system default to enable
24+
# a user to use his/her installed one.
25+
# TODO(dsjang): Currently "lib/python3.6/site-packages" is hard-coded
26+
# throughout Dockerfile. Parameterize it to avoid a version mismatch.
27+
export PYTHONPATH=${PIP_INSTALL_PREFIX_DIR}/lib/python3.6/site-packages:${PYTHONPATH}
28+
29+
# Include pip-installed binaries in PATH.
30+
export PATH=${PATH}:${PIP_INSTALL_PREFIX_DIR}/bin
31+
fi

0 commit comments

Comments
 (0)