Errors in SDR/Utils.py (source code version-3.7.0)

Hello NatCap team,
I downloaded the latest version of InVEST/SDR (source code via pip install on windows 10, 64bit), and I am having some issues with utils.py. Please see the error messages below. I tried to get around the first error but then different issues started to pop-up. In case you want to know, my input files (biophysical table/other rasters) work fine with the GUI version of the InVEST SDR module downloaded from your website.

Please let me know if you have any suggestions.

Thanks for your help,

Nitin

Errors -

C:\Users\singhnk\Documents\UVM\Labproject\InVEST>python python_script.py
Traceback (most recent call last):
File “python_script.py”, line 25, in
natcap.invest.sdr.execute(args)
File “C:\Users\singhnk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\natcap\invest\sdr.py”, line 120, in execute
args[‘biophysical_table_path’], ‘lucode’)
File “C:\Users\singhnk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\natcap\invest\utils.py”, line 454, in build_lookup_from_csv
key_field = unicode(key_field)
NameError: name ‘unicode’ is not defined (ERROR1)

C:\Users\singhnk\Documents\UVM\Labproject\InVEST>python python_script.py
Traceback (most recent call last):
File “python_script.py”, line 25, in
natcap.invest.sdr.execute(args)
File “C:\Users\singhnk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\natcap\invest\sdr.py”, line 120, in execute
args[‘biophysical_table_path’], ‘lucode’)
File “C:\Users\singhnk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\natcap\invest\utils.py”, line 474, in build_lookup_from_csv
for x in row])
File “C:\Users\singhnk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\natcap\invest\utils.py”, line 474, in
for x in row])
NameError: name ‘basestring’ is not defined (ERROR2)

C:\Users\singhnk\Documents\UVM\Labproject\InVEST>python python_script.py
Traceback (most recent call last):
File “python_script.py”, line 25, in
natcap.invest.sdr.execute(args)
File “C:\Users\singhnk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\natcap\invest\sdr.py”, line 124, in execute
for (lulc_code, table) in biophysical_table.iteritems():
AttributeError: ‘NoneType’ object has no attribute ‘iteritems’ (ERROR3)

C:\Users\singhnk\Documents\UVM\Labproject\InVEST>python python_script.py
Traceback (most recent call last):
File “python_script.py”, line 25, in
natcap.invest.sdr.execute(args)
File “C:\Users\singhnk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\natcap\invest\sdr.py”, line 148, in execute
(_TMP_BASE_FILES, churn_dir)], file_suffix)
File “C:\Users\singhnk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\natcap\invest\utils.py”, line 387, in build_file_registry
for file_key, file_payload in base_file_dict.iteritems():
AttributeError: ‘dict’ object has no attribute ‘iteritems’ (ERROR4)

Hi @nksingh, sorry for the hassle here! Based on these errors, it looks like your comes environment is running some version of python 3. Unfortunately, the natcap.invest python package is, for the moment, only available for python 2.7, so hopefully the fix should be as simple as specifying your python version as 2.7 in your environment YML file.

All that being said we’re so close to having a python3 release of natcap.invest, so look forward to that in the very near future :slight_smile: