Last active
December 28, 2017 17:41
-
-
Save karenyyng/d854662dadd2f1fa027bc87abf0a045c to your computer and use it in GitHub Desktop.
setup_conda.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------- | |
# Author: Karen Ng <mailto:[email protected]> | |
# dependency: wget | |
# usage: | |
# source install_py${PYTHON_VERSION}_${INTEL_PYTHON_VERSION}.sh | |
# | |
# Copyright (c) 2017, Intel Corporation | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions are met: | |
# | |
# * Redistributions of source code must retain the above copyright notice, | |
# this list of conditions and the following disclaimer. | |
# * Redistributions in binary form must reproduce the above copyright | |
# notice, this list of conditions and the following disclaimer in the | |
# documentation and/or other materials provided with the distribution. | |
# * Neither the name of Intel Corporation nor the names of its contributors | |
# may be used to endorse or promote products derived from this software | |
# without specific prior written permission. | |
# | |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | |
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
# | |
# You need to set the following environmental variables to use this properly: | |
# | |
# export CONDA_ENV=some_name | |
# export INTEL_PYTHON_VERSION=2018.0.0 | |
#### PY_VERSION values can be 35 or 27 | |
# export PY_VERSION=35 | |
#### PY_DOT_ERSION values can be 3.5 or 2.7 | |
# export PY_DOT_VERSION=3.5 | |
#### PY_DOT_ERSION values can be 2 or 3 | |
# export PY_MAJOR_VERSION=3 | |
#### EDITION can be `core` or `full` | |
# export EDITION=core | |
# if [[ $NERSC_HOST == "cori" ]]; then | |
# # use a directory where you have write-permission such as $SCRATCH or /global/common/project_name | |
# ENV_DIR=$SCRATCH | |
# else | |
# export DIR=$HOME/miniconda${PY_MAJOR_VERSION} | |
# export ENV_DIR=$DIR | |
# fi | |
# | |
# ------------- | |
if [[ -z $CONDA_ENV ]]; then | |
echo "$CONDA_ENV is not defined. Quitting installation script." | |
exit 1 | |
fi | |
echo "Installing Intel Python version $INTEL_PYTHON_VERSION" | |
if echo "$(uname -a)" | grep Linux ; then | |
OS=Linux | |
else | |
OS=MacOSX | |
fi | |
echo "Running on the OS = ${OS}" | |
export ACCEPT_INTEL_PYTHON_EULA=yes | |
echo 'Accepting INTEL PYTHON EULA' | |
# set up a self-contained conda if we are on a machine other than Cori | |
if [[ ! -x $HOME/miniconda3/bin/conda ]] && [[ $NERSC_HOST != "cori" ]]; then | |
[ -f Miniconda3-latest-${OS}-x86_64.sh ] || wget "https://repo.continuum.io/miniconda/Miniconda3-latest-${OS}-x86_64.sh" | |
bash ./Miniconda3-latest-${OS}-x86_64.sh -b -p $DIR -f | |
echo "Installing miniconda at $DIR" | |
fi | |
# Cori comes with its anaconda installation so we just have to load it up | |
if [[ $NERSC_HOST == "cori" ]]; then | |
# DIR="/global/common/cori/software/python/${PY_DOT_VERSION}-anaconda" | |
module load "python/${PY_DOT_VERSION}-anaconda" | |
echo "module load python/${PY_DOT_VERSION}-anaconda" | |
CONDA=conda | |
else | |
export CONDA=$DIR/bin/conda | |
fi | |
# tell conda where to find the envrionments | |
if [[ -f $HOME/.condarc ]]; then | |
mv $HOME/.condarc $HOME/.condarc.backup | |
echo 'Backing up $HOME/.condarc to $HOME/.condarc.backup' | |
fi | |
$CONDA config --add channels intel | |
echo 'Finished adding Intel channel in conda' | |
echo 'Adding proper environment paths for environment' | |
echo $'envs_dirs:' >> ${HOME}/.condarc_${CONDA_ENV} | |
echo " - ${ENV_DIR}/py${PY_VERSION}_envs" >> ${HOME}/.condarc_${CONDA_ENV} | |
echo "Appending envs_dirs at $ENV_DIR/py35_envs to ~/.condarc_${CONDA_ENV} and ~/.condarc" | |
cp ${HOME}/.condarc_${CONDA_ENV} ${HOME}/.condarc | |
if [[ ! -d $ENV_DIR/py${PY_VERSION}_envs ]]; then | |
mkdir $ENV_DIR/py${PY_VERSION}_envs | |
echo "Creating directory py${PY_VERSION}_envs at $ENV_DIR" | |
fi | |
echo "Installing libraries for $ENV_DIR" | |
$CONDA create -y -c intel -n $CONDA_ENV intelpython${PY_MAJOR_VERSION}_${EDITION}=$INTEL_PYTHON_VERSION python=${PY_MAJOR_VERSION} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment