Skip to content

Instantly share code, notes, and snippets.

@MagnusBrzenk
Last active March 7, 2021 16:09
Show Gist options
  • Save MagnusBrzenk/1ba3220f2dea3d478e2d58cd8be100c1 to your computer and use it in GitHub Desktop.
Save MagnusBrzenk/1ba3220f2dea3d478e2d58cd8be100c1 to your computer and use it in GitHub Desktop.
Bash script to install jupyterlab into a virtual environment with kernels for python3, python2 and R
#!/usr/bin/env false
######################################################################
### Script to set up single venv with kernels for python2, 3 and R
######################################################################
main() {
clear
echo ">>> Creating python3 venv"
python3 -m venv .venv
source .venv/bin/activate
echo ">>> Installing jupyter with python3 kernel"
pip install -q jupyterlab
echo ">>> Creating python2 venv"
deactivate
virtualenv -q -p python2 .venv2
source .venv2/bin/activate
echo ">>> Creating python2 kernel"
pip install -q ipykernel
echo ">>> Exporting python2 kernel"
python -m ipykernel install --prefix=$PWD/.venv #--name 'Python 2'
echo ">>> Reactivating python3 venv"
deactivate
source .venv/bin/activate
echo ">>> Installing IRkernel"
R -q -e "install.packages('IRkernel',repos='https://cran.mtu.edu/',quiet=TRUE)"
echo ">>> Creating R kernel"
R -q -e "IRkernel::installspec(prefix=paste(getwd(),'/.venv',sep=''))"
echo ">>> Finished. Here are the available kernels:"
jupyter kernelspec list
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment