Installing PCRaster with Conda¶
PCRaster is available on conda-forge and can be installed using conda. Supported platforms are Linux, macOS and Windows.
After setting up Conda you can create a new environment and install PCRaster.
To only install the latest PCRaster version use:
conda create --name pcraster -c conda-forge pcraster
conda create --name pcraster -c conda-forge python=3.10 numpy pcraster campo lue matplotlib-base spyder spotpy
Always use the conda-forge channel when installing further packages into your PCRaster environment.
If you installed previous versions of PCRaster (4.2 or older) you must remove their entries from the PATH and PYTHONPATH environment variables before activating your environment. Modifying PATH and PYTHONPATH environment variables as required for previous PCRaster versions is not necessary anymore starting from version 4.3, the settings are done automatically when you activate your environment.
Testing your installation¶
You can execute a few basic steps to check if PCRaster works properly in your conda environment. In case you have not done yet, activate your PCRaster environment. Then you can test the visualisation tool Aguila by starting it from the command prompt. It will show its help page. Afterwards start Python:
$ conda activate pcraster (pcraster) $ aguila -h (pcraster) $ python
Import the PCRaster module, print the version number and afterwards create a raster with 6 rows, 4 columns, cell length 1 and 0, 0 as origin. Fill the entire raster with random values drawn from a uniform distribution and display the result:
import pcraster as pcr pcr.__version__ pcr.setclone(6, 4, 1, 0, 0) pcr.aguila(pcr.uniform(1))
You will see that Aguila is displaying the map:
You can also test the PCRaster command line applications.
Exit the Python interpreter and type
The usage information will be shown:
(pcraster) $ pcrcalc pcrcalc 4.3.3 (linux/x86_64) USAGE: pcrcalc [options] "expression" or pcrcalc [options] -f scriptFile ( or #!: pcrcalc -F [options]+) other flags: s # : set seed (integer > 0) for random generator default is based on current time b f : overrule script bindings 1 : update timeseries files at end of each timestep r f : set run directory d f : debug mode, check MV creation on assignment comparing against clone or areamap boolean mask c : strict Case significant filename check (Unix portability) p : print profile information m : optimize with areamap MV compression l : use less memory but more temporary disk storage t : test argument substitution
Aguila fails to start on macOS¶
On newer macOS versions Aguila may fail to start up. This should be resolved by adding the following environment variable:
Import of the
pcraster module fails¶
An error message such as
Traceback (most recent call last): File "C:\Software\pcraster\pcraster-4.2.1\python\pcraster\__init__.py", line 21, in <module> from ._pcraster import * ImportError: DLL load failed while importing _pcraster: Kan opgegeven module niet vinden. During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\script.py", line 1, in <module> import pcraster as pcr File "C:\Software\pcraster\pcraster-4.2.1\python\pcraster\__init__.py", line 55, in <module> raise ImportError(msg) ImportError: The 'pcraster' module was built for Python 3.6, the version used is 3.8
indicates that an older version of PCRaster is available on the system, here located at
You need to remove the corresponding PCRaster entries of the PATH and PYTHONPATH environment variables.
After starting a new terminal you can import the