NOTE!! This pages is outdated and based on old implementations of PyWPS. The written documentation also often causes problems during installation. Please check the page Set up PyWPS in a windows environment with Anaconda.
The PyWPS software was originally developed to use under Linux (Debian). However, it is also possible to use the software in a Windows environment for example for testing purposes. To do so, Apache server has to be installed on the system. For Linux installation see this manual. Note this pages was initially written for PythonXY users. If you use anaconda bear in mind that location is no longer c:\python2.7 but c:\anaconda. Also mind the version of anaconda installed (x86 or x64 bit version).
Step 0 Python installations
Make sure Python is pre-installed on your machine, we recommend PythonXY (version 2.7, not 3.x).
After install, start a NEW command line prompt and go to the root and check if :
Python version is 2.7,Result should be like:
Show Python versionC:\>python --version Python 2.7.6
Python package magic is installed and of version 0.4.6 else see Known Installation Issues
Python-Magic package versionnrC:\>pip show python-magic --- Name: python-magic Version: 0.4.6 PyPi Version: 0.4.6 Location: c:\python27\lib\site-packages home_page: http://github.com/ahupp/python-magic Summary: File type identification using libmagic Requires: Required by(0):
- Python package lxml is installed and of version 3.3.5 else download http://www.microsoft.com/en-us/download/details.aspx?id=44266, install this c++ compiler and install lxml with this command :
pip install lxml
Python lxml packageC:\>pip show lxml --- Name: lxml Version: 3.3.5 PyPi Version: 3.4.0 Location: c:\python27\lib\site-packages home_page: http://lxml.de/ Summary: Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API. Requires: Extra Require [source]: cython(-) Extra Require [cssselect]: cssselect Extra Require [html5]: html5lib Extra Require [htmlsoup]: beautifulsoup4 Required by(5): html5lib[optional], pandas[html], astropy[optional], astropy[doc ], beautifulsoup4[optional]
Step 1 PyWPS
Download PyWPS (version 3.2.1, not 3.2.2)
Step 2 Install PyWPS
Unpack the contents of PyWPS folder and save the entire folder as c:\pywps
. Such that you have c:\pywps\wps.py
. Check if it works command line in python by navigating to c:\pywps
and execute this command:
C:\>cd pywps C:\pywps>python wps.py PyWPS NoApplicableCode: Locator: None; Value: No query string found. Content-Type: application/xml <?xml version="1.0" encoding="utf-8"?> <ExceptionReport version="1.0.0" xmlns="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"> <Exception exceptionCode="NoApplicableCode"> <ExceptionText>'No query string found.'</ExceptionText> </Exception> </ExceptionReport>
Step 3 Configure PyWPS
- Create a folder called
c:\pywps\pywps_processes
- Add the file
default.cfg
(fromc:\pywps\pywps
) into it. If you like you can insert your own information in the file.
However, do not forget to :- Set the correct path for
under [server] section.tempPath(
c:/pywps/
temp) - Set
outputPath
under [server] section.(
c:/[webserver]/htdocs/wps/wpsoutput
) - Set
processesPath
toc:/pywps/pywps_processes
- Set the
logFile
to somewhere(
c:/pywps/log
)
- Set the correct path for
The path slashes should conform to python conventions, which happen to be the same as the linux slash convention, and not the windows convention. Note that python paths should never end with a slash!.
Step 4 Configure Apache
Navigate to the Apache folder.
If the Apache web server is not installed in your machine yet, download the newest stable release of Apache (https://httpd.apache.org/download.cgi).
After installation, in the Apache folder c:\Program Files (x86)\Apache Software Foundation\Apache2.2
you find a sub folder called cgi-bin
.
Create an empty file called pywps.cgi
in this folder and insert the following code in it, after checking the python path (and correcting it: for example if you have Python2.7 installed, the first line should be #!c:\python27\python.exe
): Note for anaconda users this should be #!c:/anaconda/python.exe and the MPLCONFIGDIR should be C:/Anaconda/Lib/site-packages/matplotlib/mpl-data
#!C:\python27\python.exe import sys sys.path.insert(0, r"C:/pywps") import os os.environ['PYWPS_CFG']='C:/pywps/pywps_processes/default.cfg' os.environ['MPLCONFIGDIR']='C:/Python27/Lib/site-packages/matplotlib/mpl-data' # Note that WPS runs as apache user and not as you, so many more user variables might be needed. # Restart Apache after adding one. import wps
Step 5 Install Python PyWPS package
Install the PyWPS Python package:
- On the command line in the pywps folder
c:\pywps>
typepython c:\pywps\setup.py install
- Or open the Windows command line tool (start > run), drag and drop
setup.py
from yourc:\pywps
folder, type install after the location of the setup file and click ok. The PyWPS Python package will now be installed.)
Check if it is installed correctly into python like this :
C:\>pip show pywps --- Name: pywps Version: 3.2.1 PyPi Version: trunk Location: c:\python27\lib\site-packages\pywps-3.2.1-py2.7.egg home_page: http://pywps.wald.intevation.org Summary: PyWPS: Implementation of OGC's Web Processing Service in Python Requires: Required by(0):
Step 6 Install python-magic
Check if cygmagic.dll or cygmagic-1.dll is on your system. If not, install it via installing cygwin (http://cygwin.com/install.html). Install the appropriate version (i.e. 32bit or 64bit). You only need to install the python-magic part of cygwin. If you install all, it is very large (several Gb). You can force installation of python-magic by typing this in the search bar, see window below. NOTE if python-magic does not yield results. Try python2-magic (i.e. Python version for this version of PyWPS).
Set the path to the bin directory of cygwin and copy cygmagic-1.dll to cygmagic.dll.
NB. If you already have MinGW installed (x86 or x64), you can first try to install python-magic without having to install cygwin.
Step 7 First test of WPS
Test your WPS by starting Apache server and navigate to http://localhost/cgi-bin/pywps.cgi The result should be something similar to this, meaning that the pywps process runs correctly inside the apache web server.
<ExceptionReport xmlns="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd"> <Exception exceptionCode="NoApplicableCode"> <ExceptionText>'No query string found.'</ExceptionText> </Exception> </ExceptionReport>
Step 8 Testing WPS behavior
Now pywps runs, test for correct WPS behavior in browser using the syntax in WPS Primer. In c:\pywps\tests\processes
some example processes are included, copy its entire contents to the c:\pywps\pywps_processes
folder (that you configured as processesPath=c:/pywps/pywps_processes
in c:\pywps\pywps_processes\default.cfg
) and find out whether you can get them to run. First test the GetCapabilities request:
<wps:Capabilities service="WPS" version="1.0.0" xml:lang="en-CA" xsi:schemaLocation="http:/opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsGetCapabilities_response.xsd" updateSequence="1"> ... </wps:Capabilities>
and then executing any of the available processes
e.g. http://localhost/cgi-bin/pywps.cgi?service=wps&request=Execute&Identifier=dummyprocess&DataInputs=\[input1=42\]&version=1.0.0.
Step 9 Add wps processes
Now add your own Python processes as WPS by copying your processes to the c:\pywps\pywps_processes
folder too. Use the WPS syntax (Setting up a WPS process using PyWPS) for your python functions as in the copied examples. Change 3 things when adding a new WPS process based on these examples:
- add new file
XYZ.py
toc:/pywps/pywps_processes
- change
identifier
insideXYZ.py
- add
"XYZ.py"
toc:/pywps/pywps_processes/_
init
_.py
Known installation issues
If the GetCapabilities request gives you this error
Internal Server Error
in your html browser, please check your apache error.log in
c:\Program Files (x86)\Apache Software Foundation\Apache2.2\logs
.In some cases it might contain this error message
ImportError: No module named magic\r
. In this case please manually install the python-magic package from https://github.com/ahupp/python-magic. For your convenience we included a windows distributable win32 Python2.7 version until the official binary is available at github. Restart apache afterwards (typeservices
in your windows start menu or click small apache icon in icon tray). If you still get errors (failed to find libmagic
in the aforementioned Apache error.log) install cygwin http://cygwin.com/install.html which contains the magic dll. Set the path where thecygmagic-1.dll
residesc:\Program Files (x86)\Cygwin\bin
in the windows $PATH environment variable so magic.py can find it (bear in mind that this should be the System Variables Path setting). Now several options are available to solve this issue, these are:- If you don't want to have cygwin on your machine just copy the following dynamic link library (dll) files from the cygwin installation to the python root directory (where python.exe resides) and uninstall / remove cygwin:
cygmagic-1.dll (rename this to cygmagic.dll!!!!!)
cyggcc_s-1.dll
cygwin1.dll
cygz.dll
- Pay attention to the CPU Type installation, if you have installed a 64 bits python use 64 bits libs!!
- Final trick in case of , if all off the above does not help and your made sure that you have all correct libraries installed for the correct CPU type, you could alter the file called magic.py. Dependent on the type of python installer (for now Anaconda and PythonXY are known to the different authors of this page) this magic.py is availabe in the <pythonpath>\lib\site-packages directory. Search for the line called
'platform_to_lib =
' it should mention between [] 'magic1.dll'. Complete that list (python list) with 'cygmagic.dll'.
- If you don't want to have cygwin on your machine just copy the following dynamic link library (dll) files from the cygwin installation to the python root directory (where python.exe resides) and uninstall / remove cygwin:
In some cases it might contain this error message : ImportError: No module named Template\r\r ; You probably have installed PyWPS version 3.2.2. Please remove this version and download and install version 3.2.1.
- The following error
AttributeError: 'exceptions.ImportError' object has no attribute 'replace'\r
is caused by the fact that step 7 is not fully followed. So put some processes in your processes folder and try the GetCapabilities again. - If you run this in a Virtual windows machine (e.g. via VMWare), regular disk mappings might not work in WPS because WPS runs as another users (apache), please try references like
//vmware-host/Shared%20Folders/D/
instead of simplyD
. Errors like these for import statements in a WPS process, e.g.
import matplotlib
causesPyWPS [2014-03-19 14:58:23,112] WARNING: Could not import processes from 'pywps_processes': ImportError('No module named pwd',)
have to do with the fact that WPS runs under
apache
user, so add any required user environmental
variables toc:\Program Files (x86)\Apache Software Foundation\Apache2.2\cgi-bin\pywps.cgi
:pywps.cgios.environ['MPLCONFIGDIR']='C:/Python27/Lib/site-packages/matplotlib/mpl-data'
Notes:
- PyWPS can also be used with the Q-GIS WPS plugin by Dr. Horst Duester.
- Official documentation on PyWPS (v3.2.0) can be found here
- To install basemap you can follow the instructions here
Acknowlegdements The first version of this documentation was made by MSc student Joost Boerboom for his thesis, financed by Deltares under the Next Generation Hydro Software program executed for Rijkswaterstaat. Subsequently, this documentation was improved by Deltares in projects EMODnet chemistry, ECOSTRESS and FAST.
6 Comments
Annet Hospers
Dear all,
I am trying to implement this manual, but I failed to finalize step 7. In this step the GetCapabilities request is tested and first the Apache log file stated that he could not find libmagic. First when I tried to import this with the command prompt it failed also (while it was installed). Now (after adding paths to my environment and other changes) it works in command prompt. But still Apache is stating that it could not find libmagic. Does anyone know why this is not working? Or some things I could try?
Thanks in advance.
Kind regards,
Annet Hospers
The error.log file states this:
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] Premature end of script headers: pywps.cgi
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] Traceback (most recent call last):\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] File "C:/Apache2.2/cgi-bin/pywps.cgi", line 10, in <module>\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] import wps\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] File "C:\\pywps
wps.py", line 89, in <module>\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] if wps.parseRequest(inputQuery):\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] File "C:\\pywps\\pywps
_init_.py", line 205, in parseRequest\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] from Parser.Get import Get\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] File "C:\\pywps\\pywps\\Parser
Get.py", line 43, in <module>\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] from pywps.Process.Lang import Lang\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] File "C:\\pywps\\pywps\\Process
_init_.py", line 28, in <module>\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] import InAndOutputs\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] File "C:\\pywps\\pywps\\Process
InAndOutputs.py", line 25, in <module>\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] import magic\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] File "C:\\python27\\lib\\site-packages
magic.py", line 172, in <module>\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] raise ImportError('failed to find libmagic. Check your installation')\r
[Mon Apr 28 13:51:24 2014] [error] [client 127.0.0.1] ImportError: failed to find libmagic. Check your installation\r
Fedor Baart
This issue might be the same as listed under "Known installation issues:"
For it to work under windows we had to submit a patch to the python magic binding. You can double check if that change is in your version of magic.py. See: https://github.com/ahupp/python-magic/commit/4894efac92ae22ef125e2aedd9cf193d93918f55
Annet Hospers
Thanks for your quick reply. This change is already been made in my version of magic.py.
libmagic = None
# Let's try to find magic or magic1
dll = ctypes.util.find_library('magic') or ctypes.util.find_library('magic1') or ctypes.util.find_library('cygmagic-1')
Is there maybe something else?
Thanks in advance.
Fedor Baart
Maybe the file cygmagic-1.dll is not in your PATH.
Make sure you have installed cygwin.
You can check the PATH using the computer properties. Make sure you check the System PATH and not the user PATH (as the website is running under a different user). The PATH should contain something like c:\cygwin64\bin. In this directory there should be a file cygmagic-1.dll.
Matthijs Schaap
I had some problems as well regarding the above... make sure you use cygwin 32 with python32 and wps 32... cygwin64 does not work.
Fedor Baart
Other's have used python 64bit (from anaconda) with cygwin 64. It's important that they match.