The backend uses Python 2, the latest version of which can be found at https://www.python.org/downloads/. Python is by default not available on the windows command prompt, to append it to the PATH variable run the following
set PATH=%PATH%;C:\Python27
set PATH=%PATH%;C:\Python27\Scripts
This is not permanent and will need to be run each time command prompt is started. To permanently change this add C:\Python27
and C:\Python27\Scripts
to the Path
environment variable found at Control Panel->All Control Panel Items->System->Advanced System Settings->Environment Variables.
The default Python 2 installation on macOS and linux will include pip which is used to install libraries and other dependencies of this project. For Windows this can be installed by downloading the get-pip.py bootstrap and running
python get-pip.py
in the directory of the downloaded file.
Before running the backend ensure you have installed the python library requirements found in requirements.txt (see section below). We recommend using virtualenv to create an environment for python separate from other projects on your machine. This can be accomplished through
pip install virtualenv
To create a new virtual environment for the backend we call
virtualenv venv
and activate the virtual environment with
venv\Scripts\activate
on Windows or
. venv/bin/activate
on macOS/linux.
Two dependencies scipy and numpy can not be installed via the Python Package Index on Windows. You must download the binaries from the Unofficial Windows Binaries for Python Extension Packages. Find the numpy and scipy headings and download the required binaries for numpy 1.15.0-cp27
and scipy 1.1.0-cp27
.
pip install \path\to\numpy binary
pip install \path\to\scipy binary
To install the rest of the requirements run
pip install -r requirements.txt
while in the backend directory. This is only required at initial set up or when the requirements have changed.
LearnLytics backend uses a PostgreSQL 9 database. For local development we recommend Postgres.app for a CLI-tool. For a graphical tool we suggest pgAdmin 4. Create an empty database available at the URI postgresql://localhost/backend_db
with
CREATE DATABASE backend_db;
To set up a local database, first drop any existing tables with
DROP SCHEMA public CASCADE; CREATE SCHEMA public;
or in a graphical database manager. Then while in the project virtual environment run
# CMD
python create_metadb.py
# bash
./create_metadb.py
to initialise a new database with a user specified root user. To populate the database with mock data run
# CMD
python populate_with_mock_data.py
# bash
./populate_with_mock_data.py
For usage information use.
# CMD
python populate_with_mock_data.py -h
# bash
./populate_with_mock_data.py -h
After the requirements have been fulfilled you can start the backend by running
# CMD
python main.py
# bash
./main.py
To connect your virtualenv to PyCharm, navigate on macOS to Preferences->Project SP->Project Interpreter->gear button->Add Local->/venv/bin/python. On Windows navigate to Settings->Project SP->Project Interpreter->gear button->Add Local->/venv/Scripts/python.