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. On Debian based GNU/Linux distributions such as Ubuntu or Linux Mint, the following packages should be installed by using the package manager (e.g. sudo apt install package_name):

  • Install system libraries:
    • python3
    • python3-tk
    • tk-dev
    • build-essential
    • gfortran
    • libgfortran4
    • libgsl0-dev
    • libcfitsio-dev
    • libncurses-dev
    • libblas-dev
    • liblapack-dev
    • libatlas-base-dev
    • libfreetype6-dev
    • libpng-dev
    • libhdf5-dev
sudo apt install python3 python3-tk tk-dev build-essential \
                    gfortran libgfortran4 libgsl0-dev libcfitsio-dev \
                    libncurses-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=20.0.27
wget -c https://github.com/pypa/virtualenv/archive/$VIRTUALENV.tar.gz
tar -zxvf $VIRTUALENV.tar.gz
cd virtualenv-$VIRTUALENV
python3 virtualenv.py $PYTHON_SANDBOX
cd $SHARED_DIR
rm -rf virtualenv-$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 ipython # Alternative python shell
pip install pudb # Debugger
pip install lockfile

pip install cython # C-extensions for python
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
pip install dill # Pickle related
  • 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