A quick note of configuring a conda environment for PyWPS on Ubuntu. Test environment: Ubuntu 20.04 LTS (Focal Fossa) 64-bit, Python 3.8, PyWPS 4.4.2
Installation
Create conda environment for PyWPS:
conda create -n "pywps" python=3.8
Install PyWPS and dependencies:
#Latest PyWPS
conda install -c conda-forge pywps
#Optional packages
conda install numpy
conda install gdal
conda install -c conda-forge pillow
Install and enable Apache WSGI for Python 3:
sudo apt-get install libapache2-mod-wsgi-py3
sudo a2enmod wsgi
Configuration
Create WPS Directory /usr/local/pywps
and create pywps.wsgi
:
#!/usr/bin/env python3
import sys
sys.path.append("/usr/local/anaconda3/envs/pywps/lib/python3.8/site-packages/")
sys.path.append("/usr/local/pywps/processes")
from pywps.app.Service import Service
# processes need to be installed in PYTHON_PATH
from processes.sleep import Sleep
from processes.ultimate_question import UltimateQuestion
from processes.centroids import Centroids
from processes.sayhello import SayHello
from processes.feature_count import FeatureCount
from processes.buffer import Buffer
from processes.area import Area
processes = [
FeatureCount(),
SayHello(),
Centroids(),
UltimateQuestion(),
Sleep(),
Buffer(),
Area()
]
# Service accepts two parameters:
# 1 - list of process instances
# 2 - list of configuration files
application = Service(
processes,
['/usr/local/pywps/pywps.cfg']
Create pywps.cfg
:
According to https://pywps.readthedocs.io/en/master/configuration.html:
Create processes
directory and logs
directory:
mkdir processes
mkdir workdir
mkdir logs
chmod 777 logs
chmod 777 workdir
touch logs/pywps.log
chmod 777 logs/pywps.log
Create a configuration file /etc/apache2/sites-enabled/pywps.conf
:
# PyWPS
WSGIDaemonProcess pywps home=/usr/local/pywps user=www-data group=www-data processes=2 threads=5
WSGIScriptAlias /pywps /usr/local/pywps/pywps.wsgi process-group=pywps
<Directory /usr/local/pywps/>
WSGIScriptReloading On
WSGIProcessGroup pywps
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
Test
http://localhost/pywps?request=GetCapabilities&service=WPS
Issues
No module named gdal’’
Solution: install numpy may fix the gdal module issue.
No module named pywps.app.Service
This issue happens when the Python runtime is not being targeted to the conda environment. The message would be like:
[Wed Mar 17 11:35:24.851659 2021] [wsgi:error] [pid 79590:tid 139628017260288] [remote 10.28.140.89:50116] mod_wsgi (pid=79590): Failed to exec Python script file '/usr/local/pywps/pywps.wsgi'.
[Wed Mar 17 11:35:24.851713 2021] [wsgi:error] [pid 79590:tid 139628017260288] [remote 10.28.140.89:50116] mod_wsgi (pid=79590): Exception occurred processing WSGI script '/usr/local/pywps/pywps.wsgi'.
[Wed Mar 17 11:35:24.851782 2021] [wsgi:error] [pid 79590:tid 139628017260288] [remote 10.28.140.89:50116] Traceback (most recent call last):
[Wed Mar 17 11:35:24.851827 2021] [wsgi:error] [pid 79590:tid 139628017260288] [remote 10.28.140.89:50116] File "/usr/local/pywps/pywps.wsgi", line 3, in <module>
[Wed Mar 17 11:35:24.851896 2021] [wsgi:error] [pid 79590:tid 139628017260288] [remote 10.28.140.89:50116] from pywps.app.Service import Service
[Wed Mar 17 11:35:24.851942 2021] [wsgi:error] [pid 79590:tid 139628017260288] [remote 10.28.140.89:50116] ImportError: No module named pywps.app.Service
Solution: add sys.path.append("/usr/local/anaconda3/envs/pywps/lib/python3.8/site-packages/"
in pywps.wsgi
.
Reference
https://github.com/geopython/pywps/
https://pywps.readthedocs.io/en/master/deployment.html
https://faun.pub/how-to-set-up-conda-virtual-environments-with-apache-mod-wsgi-flask-c2043711223e