Skip to content

Local Installation for Programmers

Daniel Lee Young Ph.D edited this page Mar 3, 2020 · 9 revisions

Local Installation

Please refer to the User Manual (UM) and SOPs

Software Configuration Management (SCM) SOP for more information.

Prerequisites

Visual Studio Professional 2019 in Windows 10

  1. Windows development machine preferred
  2. Git - https://git-scm.com/downloads a. Plus any Git clients.
  3. Python 3.8.1 - https://www.python.org/downloads/ a. When installing, make sure that pip gets chosen as an additional feature.
  4. Latest version of Pip. Included with Python installation.
  5. Visual Studio 2019 - https://www.visualstudio.com/downloads/
    • The free Community Edition is sufficient.
  6. PostgreSQL v 10 or higher.
  7. PgAdmin4

Setup Virtual Environments

These steps use the Windows Command Prompt to set up the Python environments necessary for developing multiple Python projects.

  1. Add pip to your path if necessary.
  2. Install necessary packages
    • pip install virtualenv
    • pip install virtualenvwrapper
    • pip install virtualenvwrapper-win
  3. Add an environment variable WORKON_HOME to specify the path to store environments. By default, this is %USERPROFILE%\Envs
  4. Create a Food Waste virtual environment with the command mkvirtualenv gemm
  5. Switch between environments with the command workon {env_name}

Setup Python Django project in Visual Studio 2019

A fresh clone of Food Waste should not have any Visual Studio related files, such as .sln, .pyproj, .vs/, etc. If it does, then delete them. You’ll need to set up your local environment anyway.

  1. Open Visual Studio and select File > New > Project
  2. In the left pane, select Python and choose ‘From Existing Python Code’
  3. For the location, enter the file path to the python project (C:/Git/FoodWaste)
  4. Name the project.
  5. Submit and click next. Choose manage.py as the startup file and press next.
  6. On this final page, select both check boxes and change the project type to Django Web Project. Click finish.
  7. In the solution explorer, right click on Python Environments and select Add Virtual Environment.
    • Navigate the location to the virtual environment previously created (look in %USERPROFILE%\Envs). Alternatively, you can just create a new one in the default location through Visual Studio, which is inside the source code. This is okay and will be ignored by git
  8. In the solution explorer, right click on the new virtual environment and select install from requirements.txt
    • Alternatively, you can do this via command line with the following commands
      • cd /working/directory
      • workon {FoodWaste_env}
      • pip install –r requirements.txt
  9. Create a database called FoodWaste and import the latest data from the databases/ directory.
  10. Download and configure a local_settings.py file. Make sure to configure the proper Database settings.

INSTALLATION SETUP IDE

  1. Install Git @ https://git-scm.com/downloads
  2. Clone the repository to a local location. The Gateway uses C:\Git as the root directory, so the project is C:\Git\FoodWaste
  3. If the clone fails, you may need to extend the available path length and restart the cloning process:
    • From the git hub install, open Git shell (Alternatively, open Powershell.exe and cd to C:\Users\username\Documents\GitHub)
    • Type the command: git config –system core.longpaths true
*  Note: Make sure pgAdmin 4 is selected and installed.
    Command ran for importing a psql data dump:
    **psql -U postgres -d gemm -f dumpfilename**
    Or if psql isn’t in the path, we cd into the psql installation directory\bin\ (location of psql.exe) and ran
    **psql.exe-U postgres –d gemm –f “path\to\filename.sql”**
*  The installation takes a while to get started.
*  When choosing additional features, make sure that pip gets installed as well.
*  Note: There are SDK .NETFramework issues when using older VS versions.

Install VS 2019 Extensions & Updates

*  Install SDK (.NETFramework 4.5.2)
*  Install GitHub Extension for Visual Studio

Install and Setup Python Virtual Environments

*  **pip install virtualenv**
*  **pip install virtualenvwrapper**
*  **pip install virtualenvwrapper-win**
*  Create a FoodWaste virtual environment with the command **mkvirtualenv FoodWaste**

If the FoodWaste is not yet a VS project, you will need to open it in visual studio to get a proj file. Else, skip these steps

*  Open Visual Studio and select File > New > Project
*  In the left pane, select Python and choose ‘From Existing Python Code’
*  For the location, enter the file path to the python project (C:/Git/Gemm)
*  The project name should derive itself from the chosen file location, if not, give it a name.
*  Submit and click next. Choose manage.py as the startup file and press next.
*  On this final page, select both check boxes and change the project type to Django Web Project. Click finish.

Add the 'FoodWaste' virtual environment to your VS project

*  In the solution explorer on the right, right-click on 'Python Environments' and select 'Add Virtual Environment'.
*  For 'Location of the virtual environment', browse to the FoodWaste virtual environment location, usually found in 'C:\Users\%Username%\Envs\'
*  Using the checkbox, you can let VS automatically install all required pip packages.

Install Python Packages (if they weren't installed)

*  In the solution explorer, expand Python Environment, right click the FoodWaste environment, and select 'Install from requirements.txt'

The following pip packages are used and listed in requirements.txt

SETUP postreSQL SERVER

  1. Set up a PostgreSQL server if one is not already installed on the machine.
  2. Use FoodWaste.backup to import data into your local PostgreSQL.
  3. In the solution for the FoodWaste Project, edit (or create if not exists) the local_settings.py file, in the same directory as all the other python code (FoodWaste> FoodWaste).
  4. Change the credentials in DATABASES so that it will work with your local copy.

INSTALLATION & UPDATES (to server)

RHEL/FEDORA Server

PostgreSQL Install

[sudo yum install postgresql-server]

FoodWaste

Installation and updating FoodWaste Web Tool on Fedora Server. Fedora Command Line. The 'dnf' command (equivalent to apt-get)

Weekly security update commands

Update FoodWaste Web Tool from US EPA GitHub server https://github.com/USEPA/FoodWaste From root E4S folder, execute as su:

  • git add [file_names] (if any new files/directories were created)
    • git commit -m "Insert Comments Here"
    • git remote add origin https://dyoung11@github.com/USEPA/FoodWaste.git
    • git push origin master/branch_name (to merge server version with github version)
    • git pull origin master/branch_name (to merge github version with server version)
Clone this wiki locally