public

Setup IPython Notebook and Pandas for Ubuntu

  • Download Gist
setup_pandas_notebook_deb.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
#!/bin/sh -x
# Setup IPython Notebook and Pandas for Ubuntu
 
IPYTHONDIR="${VIRTUAL_ENV}/src/.ipython"
IPYTHON_NOTEBOOK_DIR="${VIRTUAL_ENV}/src/notebooks"
IPYTHON_NOTEBOOK_SH="${VIRTUAL_ENV}/bin/ipython_notebook.sh"
 
setup_python_dev () {
sudo apt-get install -y build-essential python-dev python-setuptools \
python-pip python-virtualenv virtualenvwrapper
}
 
setup_virtualenvwrapper () {
#sudo apt-get install -y virtualenvwrapper
 
_VENVW='/usr/local/bin/virtualenvwrapper.sh'
if [ -f "${_VENVW}" ]; then
grep "${_VENVW}" ~/.bashrc || \
echo "source ${_VENVW}" >> ~/.bashrc && \
export _VENVW &&
source ${_VENVW}
fi
}
 
create_virtual_env () {
echo "VIRTUAL_ENV: ${VIRTUAL_ENV}"
if [ -d "${VIRTUAL_ENV}" ]; then
echo "already in a VIRTUAL_ENV: ${VIRTUAL_ENV}"
else
#sudo apt-get install -y python-virtualenv
NAME="${1:-'ipynb'}"
if [ "${_VENVW}" -ne "" ]; then
mkvirtualenv ${NAME}
workon ${NAME}
else
export VIRTUAL_ENV="${HOME}/${NAME}"
virtualenv --no-site-packages "${VIRTUAL_ENV}"
source "${VIRTUAL_ENV}/bin/activate"
fi
fi
echo "VIRTUAL_ENV: ${VIRTUAL_ENV}"
IPYTHONDIR="${VIRTUAL_ENV}/src/.ipython"
IPYTHON_NOTEBOOK_DIR="${VIRTUAL_ENV}/src/notebooks"
IPYTHON_NOTEBOOK_SH="${VIRTUAL_ENV}/bin/ipython_notebook.sh"
}
 
setup_ipython_profile () {
export IPYTHONDIR
ipython profile create #<default>
# ipython profile list
# ipython --profile <default>
}
 
setup_ipython_sh_script () {
scriptname=${1:-"${IPYTHON_NOTEBOOK_SH}"}
echo "Wrting startup script to: $scriptname"
 
cat > "${scriptname}" << EOF
#!/bin/sh
IPYTHONDIR="${IPYTHONDIR}"
IPYTHON_NOTEBOOK_DIR="${IPYTHON_NOTEBOOK_DIR}"
mkdir -p "${IPYTHON_NOTEBOOK_DIR}"
ipython notebook \
--pylab=inline \
--ipython-dir="\${IPYTHONDIR}" \
--notebook-dir="\${IPYTHON_NOTEBOOK_DIR}" \
--secure
EOF
chmod -v +x ${scriptname}
}
 
setup_ipython () {
#apt-get readline
sudo apt-get install libzmq1 libzmq-dev
pip install ipython pyzmq tornado pygments
 
python -c 'map(__import__,"IPython zmq tornado pygments".split())'
python -c 'from IPython.external import mathjax; mathjax.install_mathjax()'
mkdir -v -p "${IPYTHONDIR}" "${IPYTHON_NOTEBOOK_DIR}"
setup_ipython_profile
setup_ipython_sh_script
}
 
setup_pandas () {
# apt-cache show pandas
sudo apt-get install -y \
python-numpy \
python-scipy \
python-matplotlib \
python-dateutil \
gfortran \
cython \
libfreetype6-dev \
libpng12-dev
 
sys_shared="/usr/share/pyshared"
sys_pkgs="/usr/lib/python2.7/dist-packages"
site_pkgs="$VIRTUAL_ENV/lib/python2.7/site-packages"
for pkg in numpy scipy dateutil; do
from="${sys_pkgs}/${pkg}"
to="${site_pkgs}/${pkg}"
rm -fv "${to}"
ln -s -v "${from}" "${to}"
done
 
pip install matplotlib
pip install pytz
pip install statsmodels
pip install --no-deps pandas
python -c 'map(__import__,"numpy scipy matplotlib pylab pandas".split())'
}
 
setup_python_dev && \
create_virtual_env && \
setup_ipython && \
setup_pandas && \
$IPYTHON_NOTEBOOK_SH

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.