Last active
March 23, 2016 14:30
-
-
Save mlgill/3559ca9de860624f49b3 to your computer and use it in GitHub Desktop.
Downloads the conda install script, creates an environment with basic scientific packages, and launches a jupyter notebook. Ideally want the environment to be cleaned up at the end.
This file contains hidden or 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
#!/usr/bin/env zsh | |
# set Linux/Darwin url | |
if [[ `uname` == "Darwin" ]]; then | |
echo "Detected Mac OS X..." | |
url="http://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh" | |
else | |
echo "Detected Linux..." | |
url="http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh" | |
fi | |
# set python version | |
# set install script name | |
script_name='miniconda.sh' | |
# set environment path | |
env_path='.miniconda_env' | |
# set environment name | |
env_name='tmp_env' | |
unset PYTHONHOME | |
unset PYTHONPATH | |
# download the installation script | |
echo "Downloading conda installation script..." | |
if [[ -e $script_name ]]; then | |
rm $script_name | |
fi | |
curl $url -s -o $script_name | |
# create temporary conda installation | |
echo "Creating temporary conda installation..." | |
if [[ -e $env_path ]]; then | |
rm -rf $env_path | |
fi | |
bash $script_name -b -f -p $env_path >> /dev/null | |
rm $script_name | |
# setup path and create environment | |
echo "Creating temporary conda environment..." | |
export PATH=$env_path:$PATH | |
# TODO: make this read an environment.yml file instead if supplied | |
$env_path/bin/conda create --quiet -y -n $env_name python numpy scipy matplotlib ipython jupyter >> /dev/null | |
# run the python environment | |
source $env_path/bin/activate $env_name | |
$env_path/envs/$env_name/bin/jupyter-notebook | |
#### THIS PART DOES NOT WORK YET #### | |
# Ideally, I'd like the notebook to launch and then wait until the jupyter kernel quites | |
# Once it quits, I'd like the conda environment to be cleaned up | |
#PID=$! | |
#wait $! | |
#while [[ -d /proc/$PID ]]; do | |
# sleep 1 | |
#done | |
# | |
## clean up the python environment | |
#echo "Cleaning up the conda installation..." | |
#source $env_path/bin/deactivate | |
# | |
#if [[ -e $env_path ]]; then | |
# #rm -rf $env_path | |
# echo "Removing the environment..." | |
#fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment