Step 1. Check python version, it should be 3.6.x. (You will probalby need to run "python3" rather than "python", which is probably still version 2.something.)
$ python3 --version
Python 3.6.5
Step 2. Install Postgres with brew, create Postgres database, and run the Postgres upon startup:
$ brew install postgresql
In case of failing initdb during install, change the ownership of the postgres dir, and re-run postinstall to make initdb work:
$ sudo chown -R `whoami` /usr/local/var/postgres
$ brew postinstall postgresql
If all went fine, start the service:
$ brew services start postgresql
Step 3. Install PostGIS and connect to database:
$ brew install postgis
$ psql postgres
Step 4. Create Postgres user and PostGIS required extensions:
# CREATE ROLE postgres WITH superuser login;
# CREATE EXTENSION postgis;
# CREATE EXTENSION postgis_topology;
# CREATE EXTENSION fuzzystrmatch;
# \q
Step 5. Install Redis:
$ brew install redis
Step 6. Clone EquiTrack repository
$ git clone https://github.com/UNICEFLebanonInnovation/EquiTrack.git .
$ git checkout etools
Step 6. Install VirtualEnv and VirtualEnvWrapper, create Virtual Environment and load Python packages
$ pip install --upgrade pip # cryptography install fails due to openssl problems in case of pip 7.x
$ pip install virtualenv
$ pip install virtualenvwrapper
$ export WORKON_HOME=~/Envs
$ export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2.7
$ mkdir -p $WORKON_HOME
$ source /usr/local/bin/virtualenvwrapper.sh
$ mkvirtualenv -p `which python3.6` env1
$ pip install -r EquiTrack/requirements/local.txt
Step 7. Set environment variables:
$ export REDIS_URL=redis://localhost:6379/0
$ export DATABASE_URL=postgis://postgres:password@localhost:5432/postgres
Step 8. Migrate database schemas and create database superuser
You may need to drop and recreate the database to start from scratch:
$ dropdb -U postgres postgres
$ createdb -U postgres postgres
Then migrate the database and add the user:
$ source ~/.virtualenvs/env1/bin/activate
$ python manage.py migrate_schemas --fake-initial --noinput
$ python manage.py createsuperuser --username=etoolusr
Import the test data:
$ bzcat db_dumps/pg_backup1_27-07-16.bz2 | sudo -u postgres nice pg_restore --verbose -F t -d postgres
Assign the test country (UAT) to the user:
$ source ~/.virtualenvs/env1/bin/activate
$ python manage.py shell
Python 3.6.5 (default, Mar 29 2018, 03:28:50)
>>> from users.models import UserProfile, Country, Office, Section
>>> from django.contrib.auth import get_user_model() as User
>>> user = User.objects.get(id=1)
>>> userp = UserProfile.objects.get(user=user)
>>> country=Country.objects.get(name='UAT')
>>> userp.country = country
>>> userp.country_override = country
>>> userp.save()
$ source ~/.virtualenvs/env1/bin/activate
$ export DATABASE_URL=postgis://postgres:password@localhost:5432/postgres
$ python EquiTrack/manage.py runserver 8080
Login to the Admin Portal using the 'etoolusr' user:
http://127.0.0.1:8080/admin/login/
Step 1:
- Once the project is loaded in PyCharm go to menu ->
PyCharm - > Preferences -> Project
- Make sure your project is chosen
- Select the python interpreter present inside of the virtualenvironment
Step 2:
- Go to menu ->
PyCharm - > Preferences -> Languages & Frameworks -> Django
- Select your project and:
- enable Django Support
- Set Django Project root
- choose base.py as the settings file
- add all of the previously mentioned environment vars
Step 3:
- Go to menu ->
Run -> Edit Configurations
- Add Django Server and name it.
- In the Configuration make sure to add the environment variables again
- Choose the python interpreter (The interpreter inside of the virtual environment)
- Choose a working Directory
Step 4:
- Quit Pycharm and restart it
http://www.gotealeaf.com/blog/how-to-install-postgresql-on-a-mac
http://jasdeep.ca/2012/05/installing-redis-on-mac-os-x/
https://virtualenv.pypa.io/en/latest/userguide.html
https://www.jetbrains.com/pycharm/help/run-debug-configuration.html
http://virtualenvwrapper.readthedocs.org/en/latest/index.html