Raster opening error in python3

I saved and executed the exact same python script that was generated through InVEST workbench application (and that worked perfectly on the workbench) on python3 but I could not get it work, I get the following error message:
Traceback (most recent call last):
File “”, line 2, in
File “/home/ceciliab/miniconda3/envs/envInVEST/lib/python3.11/site-packages/natcap/invest/annual_water_yield.py”, line 624, in execute
target_pixel_size = pygeoprocessing.get_raster_info(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/ceciliab/miniconda3/envs/envInVEST/lib/python3.11/site-packages/pygeoprocessing/geoprocessing.py”, line 2089, in get_raster_info
raise ValueError(
ValueError: Could not open C:\Users\barouill\input-data\LULC_2018_Clip.tif as a gdal.OF_RASTER


I already checked the following aspects:

  1. the tif files are projected raster with the unit of projection in m
  2. I created a new environment to run the model and tried to update the gdal packages

Note that I used the latest version of natcap.invest

Hi @cbarouillet,

Thanks for posting and welcome to the forum! Could you share what operating system you’re on and a little about the differences in file paths from what you posted?

For instance it looks like the script can’t find:

C:\Users\barouill\input-data\LULC_2018_Clip.tif

But it seems your python environment is set up in a different system:

/home/ceciliab/miniconda3/envs/envInVEST/lib/python3.11

I just want to make that from where your python script is being called, it can access that C: drive location.

Cheers,

Doug

Hello Doug,

Thank you for your quick response and warm welcome :slight_smile:

Please find below the information that you need:

Microsoft windows (11 Pro)

I use WSL (Windows Subsystem for Linux) to execute my code, hence the python path:
/home/ceciliab/miniconda3/envs/envInVEST/lib/python3.11

Do you think that’s why I have an issue with accessing to the c: drive?

Hi @cbarouillet,

That could be the issue. If you’re able to, could you try copying your data into your WSL home folder, updating the paths in your script, and trying to run?

I actually have WSL too, so will try to replicate your issue.

Cheers,

Doug

I believe it is also possible to reference the C: drive from WSL, but the path should be something like /mnt/c/. More details here: command line - Where is the C drive in the WSL? - Super User

1 Like

That’s a great point Dave. The paths generated in the script from the InVEST Workbench won’t make sense inside of WSL. So you can likely keep your data where it is, but will need to update your paths in the script to reflect the /mnt/c structure Dave mentioned.

Let us know if that works!

Doug

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