-
Notifications
You must be signed in to change notification settings - Fork 69
Creating install packages for Windows
pip install pyinstaller
Edit a file to make PyInstaller set the correct api version: In the Python installation folder (for example OSGeo4W64\apps\Python37) in Lib\site-packages\PyInstaller\loader\rthooks, edit the file pyi_rth_qt4plugins.py.
After the lines:
import os
import sys
Insert the following lines:
os.environ['QT_API'] = 'pyqt'
import sip
sip.setapi("QString", 2)
sip.setapi("QVariant", 2)
sip.setapi("QDate", 2)
sip.setapi("QDateTime", 2)
sip.setapi("QTextStream", 2)
sip.setapi("QTime", 2)
sip.setapi("QUrl", 2)
Edit the end of this file to comment out trying PySide, then import from PyQt4 differently:
#try:
# from PySide.QtCore import QCoreApplication
#except ImportError:
from PyQt4.QtGui import QApplication
# We set "qt4_plugins" as only one path for Qt4 plugins
QApplication.setLibraryPaths([os.path.abspath(d)])
Edit the QT Console file Lib\site-packages\qtconsole\qt_loaders.py to insert "return True" at the top of the function has_binding. (Otherwise the checking it does will fail in the pyinstaller package and the program will not run.)
The source code needs to be checked out of GitHub. These instructions assume it is checked out into ~\SWMM-EPANET_User_Interface, a folder that contains, among other things, a folder named src. In place of the tilde at the beginning, use the full path while following these instructions.
Edit the pyinstaller specification file ~\SWMM-EPANET_User_Interface\src\ui\SWMM\frmMainSWMM.spec (or EPANET\frmMainEPANET.spec) in two places. First, at the top, change pathex to match where Lib\site-packages and ~\SWMM-EPANET_User_Interface\ are on your computer, then, near the bottom, make sure the pybin = '/OSGeo4W64/bin/' matches where the DLLs listed are located.
Open an OSGeo4W64 Shell. Make sure the full path to the src folder is first in PYTHONPATH environment variable, followed by where Python is installed, for example:
set PYTHONPATH=~\SWMM-EPANET_User_Interface\src;C:\OSGeo4W64\apps\qgis\python;C:\OSGeo4W64\apps\qgis\python\plugins;C:\OSGeo4W64\apps\Python27\DLLs;C:\OSGeo4W64\apps\Python27;C:\OSGeo4W64\apps\Python27\lib;C:\OSGeo4W64\apps\Python27\lib\site-packages
Next, change into the directory containing the model-specific main form, remove any previously created package, and run pyinstaller. For SWMM:
cd SWMM-EPANET_User_Interface\src\ui\SWMM
rmdir /S /Q build dist
pyinstaller frmMainSWMM.spec --clean
For EPANET, these steps are similar:
cd SWMM-EPANET_User_Interface\src\ui\EPANET
rmdir /S /Q build dist
pyinstaller frmMainEPANET.spec
It is normal for there to be several warnings, including libzmq not found. This will take some time to complete and it will create two folders: build and dist. The build folder can be ignored or deleted. The dist folder contains one folder which has all that is needed to run the software, with the main executable named after the main form. For SWMM, this folder will be SWMM-EPANET_User_Interface\src\ui\SWMM\dist\SWMM-UI, for EPANET it will be SWMM-EPANET_User_Interface\src\ui\EPANET\dist\EPANET-UI. The next steps call this folder *-UI. Copy a few additional items into this folder before proceeding:
Test by running the executable SWMM-UI.exe or EPANET-UI.exe. If you are very fortunate, the main window of the application will open.
If the installed version has a side-by-side error, rebuild the package and add --clean to the end of the pyinstaller command. This clears out pyinstaller's cache which may contain stale items.
Optional: Remove any unnecessary libraries included by PyInstaller. Sometimes PyInstaller includes more than the application needs. After removing libraries that seem unnecessary, test all of the features of the application to make sure everything still works.
The dist\frmMain* folder can be zipped up into an archive and sent to anyone running 64-bit Windows 7 or newer and they can unzip and run it. (See also the Inno Setup configuration file described below for additional files that are included in the provided packages.)
For user convenience, the additional step can be taken of building an Inno Setup install package from this folder. Inno Setup is a free installer for Windows and is available at:
http://www.jrsoftware.org/isinfo.php
The Inno Setup configuration file for building each package is included in the repository:
https://github.com/USEPA/SWMM-EPANET_User_Interface/blob/master/src/ui/SWMM/SWMM-UI.iss
https://github.com/USEPA/SWMM-EPANET_User_Interface/blob/master/src/ui/EPANET/EPANET-UI.iss