Tutorial to install the latest version of NES

In this guide, we will demonstrate how to install and configure NES in a Python virtual environment. We’ll then set up PostgreSQL and Apache.

Important technical information

  • This guide walks through an installation by using packages available through Debian 9 (code name: Stretch), but can easily be adapted to other Unix operating systems.
  • Using virtualenv to install NES is recommended. This is because when you use virtualenv, you create an isolated environment with its own installation directories.
  • Latest version of NES works only with Python 3.
  • For demonstration purposes, we will use the /usr/local directory to deploy NES. This directory seems to be the right place according to the Linux Foundation.

Initial setup

  1. Before running through the steps of this tutorial, make sure that all of your repositories are up to date:

    apt-get update
  2. Install some packages:

    apt-get install python-pip git virtualenv graphviz libpq-dev python-dev
    apt-get build-dep python-psycopg2
  3. Create the virtualenv (check the correct python version you are using):

    cd /usr/local
    virtualenv nes-system -p /usr/bin/python3.5
  4. Run the following to activate this new virtual environment:

    source nes-system/bin/activate
  5. Next steps will be executed inside virtualenv:

    cd nes-system
  6. Clone the NES. Check the latest TAG version here:

    git clone -b TAG-X.X https://github.com/neuromat/nes.git
  7. Install additional python packages:

    cd nes/patientregistrationsystem/qdc/
    pip install -r requirements.txt

Deploying NES with Apache, PostgreSQL and mod_wsgi

  1. Install the packages:

    apt-get install apache2 libapache2-mod-wsgi-py3 postgresql
  2. Create user and database (you will use this user/password/database in the next step):

    su - postgres
    createuser nes --pwprompt --encrypted
    createdb nes --owner=nes
  3. Use this template to create a file called settings_local.py and configure the database:

    cd /usr/local/nes-system/nes/patientregistrationsystem/qdc
    nano qdc/settings_local.py

Edit the database to use the user/password/database created in the previous step:

# Database
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'nes',
        'USER': 'nes',
        'PASSWORD': 'your_password',
        'HOST': 'localhost',
  1. Create tables:

    python manage.py migrate
  2. Create superuser:

    python manage.py createsuperuser
  3. Copy wsgi_default.py file to wsgi.py file and edit wsgi.py:

    cp wsgi_default.py wsgi.py
    nano qdc/wsgi.py

The file must contain:

# -*- coding: utf-8 -*-

WSGI config for qdc project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
import os
import sys
import site

# Add the site-packages of the chosen virtualenv to work with

# Add the paths according to your installation
paths = ['/usr/local', '/usr/local/nes-system', '/usr/local/nes-system/nes', '/usr/local/nes-system/nes/patientregistrationsystem', '/usr/local/nes-system/nes/patientregistrationsystem/qdc',]

for path in paths:
    if path not in sys.path:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qdc.settings")

# Activate virtual env

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
  1. Create a virtual host:

    nano /etc/apache2/sites-available/nes.conf

After, insert the following content remembering that the paths and the ServerName provided should be changed according to your installation:

<VirtualHost *:80>
    ServerName nes.example.com
    WSGIProcessGroup nes

    DocumentRoot /usr/local/nes-system/nes/patientregistrationsystem/qdc

    <Directory />
            Options FollowSymLinks
            AllowOverride None

    Alias /media/ /usr/local/nes-system/nes/patientregistrationsystem/qdc/media/

    <Directory "/usr/local/nes-system/nes/patientregistrationsystem/qdc">
            Require all granted

    WSGIScriptAlias / /usr/local/nes-system/nes/patientregistrationsystem/qdc/qdc/wsgi.py application-group=%{GLOBAL}
    WSGIDaemonProcess nes lang='en_US.UTF-8' locale='en_US.UTF-8'

    Alias /img/ /usr/local/nes-system/nes/patientregistrationsystem/qdc/img/

    ErrorLog ${APACHE_LOG_DIR}/nes_ssl_error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/nes_ssl_access.log combined


note the attribute “application-group=%{GLOBAL}”, which is usually not required. It is important to configure it because of the mne library, as explained here.

note the lines with the WSGIProcessGroup and WSGIDaemonProcess directives.They are important to configure the locale used by external libraries, as pydot. Without these directives, special characteres used by, for example, pydot, can not be accepted and an exception could be thrown. The tips were get here and here the wsgi_mod configurations are explained. To configure the WSGIDaemonProcess directive properly, check the encode running the command “echo $LANG” in the terminal. Sometimes the server uses the “pt_BR.UTF-8”, e.g.

  1. Loading initial data (Look at Script for creating initial data to see more details):

    chmod +x add_initial_data.py
    python manage.py shell < add_initial_data.py
    python manage.py loaddata load_initial_data.json
  2. Managing static files:

    mkdir static
    nano qdc/settings_local.py
  3. Edit the STATIC_ROOT line:

    STATIC_ROOT = '/usr/local/nes-system/nes/patientregistrationsystem/qdc/static'
  4. Collects the static files into STATIC_ROOT:

    python manage.py collecstatic
  5. Create the media directory:

    mkdir media
  6. Change the owner of the directories .git and patientregistrationsystem:

    cd /usr/local/nes-system/nes/
    chown -R www-data .git
    chown -R www-data patientregistrationsystem
  7. Enable the virtual host:

    a2ensite nes
    systemctl reload apache2