APT + VirtualEnv

A Virtual Environment is a tool to keep the libraries required by a project in separate place. It uses the basic system python installation but it will compile and install the required python libraries into an isolated directory.

  • Install system libraries:
    • python (2.7.5 or higher but not 3.x branch)
    • python-tk
    • tk-dev
    • build-essential
    • gfortran (4.8.4 or higher)
    • libgsl0-dev
    • libcfitsio3-dev
    • libncurses5-dev
    • libblas-dev
    • liblapack-dev
    • libatlas-base-dev
    • libfreetype6-dev
    • libpng-dev
    • libhdf5-dev
sudo apt-get install python-tk tk-dev build-essential gfortran \
                        libgsl0-dev libcfitsio3-dev libncurses5-dev \
                        libblas-dev liblapack-dev libatlas-base-dev \
                        libfreetype6-dev libpng-dev libhdf5-dev
  • Prepare a virtualenv in $HOME/shared/py/:
export SHARED_DIR=$HOME/shared/
export PYTHON_SANDBOX=$SHARED_DIR/py
mkdir -p $PYTHON_SANDBOX

cd $SHARED_DIR
export VIRTUALENV=15.0.2
wget -c https://github.com/pypa/virtualenv/archive/$VIRTUALENV.tar.gz
tar -zxvf $VIRTUALENV.tar.gz
cd $VIRTUALENV
python virtualenv.py $PYTHON_SANDBOX
cd $SHARED_DIR
rm -rf $VIRTUALENV $VIRTUALENV.tar.gz
  • Install required python libraries in the virtualenv:
source $PYTHON_SANDBOX/bin/activate

export LC_ALL=C
unset LDFLAGS

# Upgrade all
pip freeze --local | grep -v '^\-e' | cut -d = -f 1  | xargs -n1 pip install -U

pip install numpy # Fundamental scientific computation
pip install scipy # Tools for scientific computation
pip install matplotlib # Plots
pip install astropy # Library for Astronomy
pip install jupyter # Alternative python shell (includes ipython)
pip install pudb # Debugger
pip install lockfile

pip install cython # C-extensions for python
pip install sampy # IVOA Simple Application Messaging protocol (e.g. TOPCAT communication)
pip install scikit-learn # Machine learning algorithms
pip install tables # required by pandas to support HDF5
pip install pandas # Data analysis library

pip install patsy # required by statsmodels
pip install statsmodels # Statistics
  • Edit $HOME/.bashrc to add:
# ------------------------------------------------------------------------------
# Locally installed python (iSpec)
# ------------------------------------------------------------------------------
export SANDBOXPATH=$HOME/shared
export PATH=$SANDBOXPATH/bin:$PATH
export PYTHONPATH=$SANDBOXPATH/lib/python2.7/site-packages:$PYTHONPATH
export LD_LIBRARY_PATH=$SANDBOXPATH/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$SANDBOXPATH/lib/pkgconfig:$PKG_CONFIG_PATH
py_setup() {
    source $HOME/shared/py/bin/activate
}
py_forget() {
    deactivate
}
source $HOME/shared/py/bin/activate
  • Edit $HOME/.bash_profile to add:
source $HOME/.bashrc
  • Download iSpec source code, decompress it and move to $HOME/shared. Open a terminal in the iSpec directory and run:
make clean
make spectrum
make turbospectrum
make moog