I’m trying to run InVEST Carbon model from a Python script generated from the model GUI but I got the following error:
C:\Users\ASIL>C:\Python27\python.exe C:\Users\ASIL\Desktop\BRGX_InVEST_dataset\python_script.py
Traceback (most recent call last):
File “C:\Users\ASIL\Desktop\BRGX_InVEST_dataset\python_script.py”, line 26, in
natcap.invest.carbon.execute(args)
File “C:\Python27\lib\site-packages\natcap\invest\carbon.py”, line 180, in execute
_accumulate_totals(file_registry[output_key]), ‘Mg of C’,
File “C:\Python27\lib\site-packages\natcap\invest\carbon.py”, line 238, in _accumulate_totals
for _, block in pygeoprocessing.iterblocks(raster_path):
File “C:\Python27\lib\site-packages\pygeoprocessing\geoprocessing.py”, line 2582, in iterblocks
“(path, band_index), received %s” % repr(raster_path_band))
ValueError: raster_path_band not formatted as expected. Expects (path, band_index), received u’C:\Users\ASIL\Desktop\BRGX_InVEST_dataset\Output\tot_c_fut_run1.tif’
But when I run the model from the GUI no error occurs! Can you help me please?
This looks like an incompatibility between the versions of natcap.invest and of pygeoprocessing that are installed in your python environment. What versions of each do you have installed?
I notice that you have a Python 2.7 environment. The latest releases of natcap.invest and pygeoprocessing no longer support Python 2.7 and require at least Python 3.6.
Upgrading to Python3, natcap.invest 3.8.0 and pygeoprocessing 1.9.2 might be the best approach. But if you do want to stick with Python 2.7, I can advise on which versions should be compatible with one another.
Yes, you are right, I have tried to run the InVEST 3.5 (because I needed to use the old ScenGen that is only available in the 3.5 version). However, I remember that I had previously installed the natcap.invest and ‘pygeoprocessing’ for the InVEST v.3.6 to run a Python script in the Carbon model that J. Douglass (from NatCap team) helped me to implement…
Well, at the moment I would like to run InVEST with Python 2.7. Yes, please, I would appreciate your advice regarding the best option to use. Thank you!
Actually, I might be mistaken there. I think you will actually need pygeoprocessing==0.3.3, which is the version that we shipped with the invest user-interface, at the time.
The backwards-incompatible change that is the cause of your ValueError came in version 0.4, according to the changelog.
@dave Interestingly, it looks like InVEST 3.5 shipped with pygeoprocessing==0.6.0, at least if invest-3-x86/package_versions.txt is to be trusted. This was a time when we also vendored pygeoprocessing==0.3.3, but that was only used by some of the models, and I guess not carbon.
So @Angelo, I’d suggest pip install pygeoprocessing==0.6.0 to get the same version of pygeoprocessing that appeared to ship with InVEST 3.5.0.