Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

2 Getting Started as a Developer in Python 3

michelleannesimon edited this page Sep 9, 2020 · 3 revisions

Windows is the original development platform and is the one documented here. If you are developing on another platform, please use these instructions as a starting point and share with us the particular steps needed on your platform.

Install software to access GitHub

There are several options available, some with command-line access and others with Explorer shell integration or stand-alone GUIs. You can download git software from https://git-scm.com/downloads.

Install PyCharm Community IDE

https://www.jetbrains.com/pycharm/download/ You can download the 'Community' version. There is no need for the professional version. In addition to PyCharm, you can use your favorite Python development environment.

Install QGIS

  1. Visit https://qgis.org/en/site/forusers/download.html and under "Download for Windows", click the "QGIS Standalone Installer (64bit)" to download the "QGIS-OSGeo4W-Version-Setup-x86_64.exe" installer program.

  2. Run the installer and choose to install into the C:\OSGeo4W64\ directory and then accept all other default settings. We don't recommend install to a remote network directory. Also, one does NOT need to install the sample datasets.

  3. In Control Panel-> system and security -> system -> advanced system setting - > Environment Variable under Advanced. Then at System variable, click” new...”, put the “variable name”, and “variable value” For example, “OSGEO4W_ROOT=C:\OSGeo4W64”, is variable name is OSGEO4W_ROOT, and variable value is C:\OSGeo4W64 (Note: PATH will likely already have a value. You can keep this value by putting the new value first, then a semicolon, then the existing value. Remove any existing parts of the path that reference Anaconda or Python. Some of the environmental variables below might be redundant.)

  • OSGEO4W_ROOT=C:\OSGeo4W64
  • PYTHONHOME=C:\OSGeo4W64\apps\Python37
  • PYTHONPATH=C:\OSGeo4W64\apps\qgis\python;C:\OSGeo4W64\apps\Python37\lib;C:\OSGeo4W64\apps\Python37\DLLs
  • QGIS_PREFIX_PATH=C:\OSGeo4W64\apps\qgis
  • QT_PLUGIN_PATH=C:\OSGeo4W64\apps\qgis\qtplugins;C:\OSGeo4W64\apps\qt5\qtplugins;C:\OSGeo4W64\apps\qt5\qtplugins\platforms;
  • PATH=C:\OSGeo4W64\apps\qt5\qtplugins;C:\OSGeo4W64\apps\qt5\qtplugins\platforms;C:\OSGeo4W64\bin;C:\OSGeo4W64\apps\qgis\bin;C:\OSGeo4W64\apps\qgis\python\PyQt5;C:\OSGeo4W64\apps\Python37;C:\OSGeo4W64\apps\Python37\Scripts;C:\OSGeo4W64\apps\Qt5\bin;
  • O4W_QT_PLUGINS=C:\OSGeo4W64\apps\Qt5\plugins
  • O4W_QT_PREFIX=C:\OSGeo4W64\apps\Qt5
  • O4W_QT_TRANSLATIONS=C:\OSGeo4W64\apps\Qt5\translations
  • O4W_QT_LIBRARIES=C:\OSGeo4W64\apps\Qt5\lib
  • O4W_QT_HEADERS=C:\OSGeo4W64\apps\Qt5\include
  • O4W_QT_DOC=C:\OSGeo4W64\apps\Qt5\doc
  • O4W_QT_BINARIES=C:\OSGeo4W64\apps\Qt5\bin

At this point, git clone the repo into C:\dev folder and then check out the 'dev-ui-py3qt5' branch, you should be able to open the project from PyCharm.

You will need to install additional libraries: Pandas, tornado, which can be installed from within PyCharm under the 'Setting::Project Interpreter' option.

Get source code from GitHub

Using PyCharm:

Start PyCharm, click “Check out from Version Control”, choose GitHub.
Log in and choose whether to save your password or use a master password.
Repository URL: https://github.com/USEPA/SWMM-EPANET_User_Interface.git
Directory: choose the parent directory to put the new directory in.
Directory Name: recommend leaving it as the default: SWMM-EPANET_User_Interface
Press Clone. Answer Yes when asked whether to open the directory.
If you do not see the project files, use View/Tool Windows/Project.
This is the latest release version. For the development version, find “Git: master” in the status bar in the lower right part of PyCharm, click it, choose another branch such as origin/dev or origin/dev-ui-py3qt5, “Checkout as new local branch”, Enter name of new branch: keep the default name
OK

  • In PyCharm, if you do not see the project files, use View/Tool Windows/Project.
  • In the Project view, right-click folder "src" and choose "Mark Directory As"/"Sources Root"
  • Right-click the top item in the Project view "SWMM-EPANET_User_Interface..." and "Mark Directory As"/"Sources Root"
  • File/Settings/Build, Execution, Deployment/Console/Python Console: check "Add source roots to PYTHONPATH", press OK.
  • File/Settings/Project:.../Project Interpreter: choose C:\OSGeo4W64\apps\Python37\python.exe, press OK.
  • Wait while PyCharm searches through the Python folders. (Status is in bottom bar of PyCharm.)
  • This can take a long time. You can look at code while this happens, but need to wait to run after it completes.
  • In the Project window under src\ui Right-click “SWMM/frmMainSWMM.py” or EPANET/frmMainEPANET, and choose Debug.
  • Green “Play” button runs the last thing you chose to run, “Bug” button next to it runs in debug mode.

Install SWIG SWMM Output API from wheel

  1. Click to download SWIG SWMM Output API wheel file: swmm.output-0.4.0.dev2-cp37-cp37m-win_amd64.whl and save it to a directory of your choosing.

  2. Inside PyCharm, open python console (Tools-> Python Console... menu option), then type in the following code to install the downloaded SWMM output api whl:

import pip
def install_whl(path):
    pip.main(['install', path])

wpath = "C:/path/to/whl/file/swmm.output-0.4.0.dev2-cp37-cp37m-win_amd64.whl"
install_whl(wpath)

or

if QGIS' python install from OSGeo4W is configured properly, i.e. the command 'pip' is recognized in Windows command console, one can directly install the whl via the following command:

pip install /path/to/whl/file/swmm.output-0.4.0.dev2-cp37-cp37m-win_amd64.whl

which will install the swmm.output library into C:\OSGeo4W64\apps\Python37\Lib\site-packages directory.

if it is installed successfully, then the swmm.output python namespace will be available in the program.

THIS IS THE END OF INSTRUCTIONS FOR NORMAL DEVELOPMENT SETUP

Below are specialized instructions for unusual situations:

Code Documentation Generation

If you are going to generate documentation with Doxygen:
The additional package doxypypy is recommended. (See https://github.com/Feneric/doxypypy.):

pip install doxypypy

Create batch file ~\Anaconda2\Scripts\py_filter.bat containing one line:

doxypypy -a -c %1

Clone this wiki locally