How to setup a fresh install of Ubuntu 18.04 for Python for sciences

This is just an example (2018-07-10), but it is useful for me (Pierre Augier) to have this page, so it may be useful to others.

  • Install some useful compilers, libraries and utilities:

    sudo apt install \
      clang-6.0 gfortran cmake \
      libpng-dev libfftw3-dev libfftw3-mpi-dev \
      libhdf5-dev libopenmpi-dev \
      qt5-default \
      curl ack meld pandoc \
      fish \
      python2.7 python-pip \
      git emacs \
  • Setup Bash (.bashrc and .bash_aliases)

  • Setup (if you want Fish!):

    chsh -s $(which fish)
    echo 'set -gx PATH $PATH $HOME/.cask/bin $HOME/.local/bin/' >> ~/.config/fish/
  • Install miniconda:

    bash ./
  • To build CPython, we first have to modify a file (see

    sudo apt edit-sources


    sudo apt update
    sudo apt build-dep python3.6
  • Install pyenv (see

    git clone ~/.pyenv

    Then, for Bash:

    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc
    exec "$SHELL"

    And for Fish, see (It’s a bit tricky so read carefully. The file ~/.config/fish/conf.d/ is needed).

  • Build nice Python versions and use Python 3.6 or 3.7:

    pyenv install 3.6.6
    pyenv install 3.7.2
    pyenv install pypy3.5-6.0.0
    pyenv global 3.7.2  # or 3.6.6

    Then install several packages (as wheels) using pip:

    pip install --upgrade pip
    pip install pipenv
    pip install pytest coverage
    pip install ipython jupyterlab
    pip install numpy scipy matplotlib pandas ipympl
    pip install h5py h5netcdf
    pip install imageio pims
    pip install cython mako colorlog pythran
    pip install mpi4py
    pip install future
    pip install pyfftw
    pip install pylint flake8 mypy black yapf
    pip install trio
    pip install sphinx numpydoc sphinx-rtd-theme
    pip install pyqt5
    pip install spyder
    pip install pyqtgraph
    pip install opencv-python
    pip install scikit-image scikit-learn

    Note that pip install numpy installs a numpy wheel containing openblas.

  • More Jupyter:

    sudo apt install nodejs npm
    jupyter labextension install @jupyter-widgets/jupyterlab-manager
    jupyter labextension install jupyter-matplotlib
    jupyter labextension install @ijmbarr/jupyterlab_spellchecker
    sudo apt install chromium-browser
    jupyter-lab --generate-config
    echo 'c.NotebookApp.browser = "/usr/bin/chromium-browser"' >> ~/.jupyter/
  • Install

  • Setup ~/.pythranrc:

    wget -O ~/.pythranrc

    Note that with this setup, Pythran needs clang and openblas (which have been install previously).

  • Fix Gnome:

    sudo apt install chrome-gnome-shell gnome-tweak-tool
  • Install Latex:

    sudo apt install dvipng texlive-latex-extra texlive-fonts-recommended texlive-fonts-extra

If needed

  • Install GMT 6 and gmt-python:

    sudo apt install gmt-gshhg libgdal-dev libpcre2-dev libnetcdf-dev ghostscript
    git clone
    cd gmt/
    cp cmake/ConfigUserTemplate.cmake cmake/ConfigUser.cmake
    mkdir build
    cd build/
    cmake -DCMAKE_INSTALL_PREFIX=/usr/share/gmt-6 -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
    make -j4
    sudo make -j4 install
    pip install

    Then, set the environment variables PATH and LD_LIBRARY_PATH as needed by modifying your ~/.bashrc.