Error running InVEST model with empty workspace via Python script

What is the issue or question you have?

TL;DR: Python SWY cannot run from scratch using an empty workspace since it cannot built the taskgraph.db file. It needs to run in a worksapce where the workbench version has already been ran and built a taskgraph.db file.

I cannot run SWY directly from python file without having ran the model, even a dummy one, in the standard workbench before. InVEST python cannot solve the taskgraph task, says it is locked or corrupted, BUT if the workbench version has been ran before and have put a non corrupted taskgraph database in the workspace before, the python version runs without trouble.

What do you expect to happen?

I think something is broken in the python excecutable, or is it supposed to be like this? Run Workbench first, then you can run python version? I don’t think so, or is it?

What have you tried so far?

you can replicate this error. I just cannot make the python code work from scratch. I need to run the workbench model first so the taskgraph.db file is working.

Here is the complete model files plus configuration for workbench:

And here is the python file:

Upload the logfile using the :outbox_tray: button

No log file, since it crahes, but here are two typical errors from the console:

Error 1:

C:\Users\jleon\anaconda3\envs\invest\Lib\site-packages\natcap\invest_init_.py:34: FutureWarning:
natcap.invest requires GDAL exceptions to be enabled. You must
call gdal.UseExceptions() to avoid unexpected behavior from
natcap.invest. A future version will enable exceptions on import.
gdal.UseExceptions() affects global state, so this may affect the
behavior of other packages.
warnings.warn((‘’’
02/28/2025 21:11:04 (natcap.invest.seasonal_water_yield.seasonal_water_yield) seasonal_water_yield.execute(601) INFO prepare and test inputs for common errors
Traceback (most recent call last):
File “D:\GIS_DATA\WB\GEOAZJ\SWY\Python_scripts\GEOAZJARM_SWY_BAU.py”, line 52, in
natcap.invest.seasonal_water_yield.seasonal_water_yield.execute(args)
File “C:\Users\jleon\anaconda3\envs\invest\Lib\site-packages\natcap\invest\seasonal_water_yield\seasonal_water_yield.py”, line 645, in execute
task_graph = taskgraph.TaskGraph(
^^^^^^^^^^^^^^^^^^^^
File “C:\Users\jleon\anaconda3\envs\invest\Lib\site-packages\taskgraph\Task.py”, line 336, in init
local_version = _execute_sqlite(
^^^^^^^^^^^^^^^^
TypeError: ‘NoneType’ object is not subscriptable
02/28/2025 21:11:05 (taskgraph.Task) Task._terminate(852) ERROR ignoring an exception that occurred during _terminate
Traceback (most recent call last):
File “C:\Users\jleon\anaconda3\envs\invest\Lib\site-packages\taskgraph\Task.py”, line 842, in _terminate
if self._n_workers >= 0:
^^^^^^^^^^^^^^^
AttributeError: ‘TaskGraph’ object has no attribute ‘_n_workers’

Error 2:

02/28/2025 21:34:29 (taskgraph.Task) Task._execute_sqlite(1594) WARNING TaskGraph database is locked because another process is using it, waiting for a bit of time to try again
02/28/2025 21:34:32 (taskgraph.Task) Task._execute_sqlite(1594) WARNING TaskGraph database is locked because another process is using it, waiting for a bit of time to try again
02/28/2025 21:34:35 (taskgraph.Task) Task._execute_sqlite(1594) WARNING TaskGraph database is locked because another process is using it, waiting for a bit of time to try again

Hi @JLeon, thanks for sharing these details. This is not expected behavior. It seems to be related to an issue in the latest release of sqlite (3.49.1).

Can you please try the following:

  1. Delete the taskgraph_cache directory from the workspace.
  2. In the conda environment you are using to run InVEST, downgrade sqlite to 3.48.0.
  3. Try running the model again.

That should resolve your issue; if not, please let us know!

2 Likes

Thanks!, yes, downgrading sqlite using Navigator solve it. it is working now.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.