Run model script error

In order to run the habitat quality model repeatedly, I get an error when I try to automatically generate and run a python script from the model.
My python environment is 3.6 and all necessary libraries are installed. Please let me know how to run this script

Hi @aliasgis -

Please post the python script that you are trying to run, and the error message that you get, so we have some information to work with. Thanks.

~ Stacie

2 Likes

The script is shown below.
Thank you
=--------scrpt---------------
import natcap.invest.habitat_quality

args = {
u’access_vector_path’: u’C:/InVEST_3.7.0_x86/HabitatQuality/access_samp.shp’,
u’half_saturation_constant’: u’0.1’,
u’lulc_cur_path’: u’C:/InVEST_3.7.0_x86/HabitatQuality/lc_samp_cur_b.tif’,
u’sensitivity_table_path’: u’C:/InVEST_3.7.0_x86/HabitatQuality/sensitivity_samp.csv’,
u’suffix’: u’’,
u’threat_raster_folder’: u’C:\InVEST_3.7.0_x86\HabitatQuality’,
u’threats_table_path’: u’C:/InVEST_3.7.0_x86/HabitatQuality/threats_samp.csv’,
u’workspace_dir’: u’C:\Users\Kim\Documents\habitat_quality_workspace’,
}

if name == ‘main’:
natcap.invest.habitat_quality.execute(args)

error
Traceback (most recent call last):
File “Habitat.py”, line 6, in
import natcap.invest.habitat_quality
ModuleNotFoundError: No module named ‘natcap’

Hello,

From the error message, it looks like you don’t have the natcap.invest python package installed. Have a look at https://invest.readthedocs.io/en/latest/installing.html#installing-the-latest-development-version, but try using this natcap.invest zip file instead (since you’re using python 3.6): https://storage.googleapis.com/releases.naturalcapitalproject.org/invest/3.7.0.post366%2Bhc94dfedffddd/natcap.invest-3.7.0.post366%2Bhc94dfedffddd.zip

Note that this is a source install … you’ll need Visual Studio installed in order to compile it. If that’s too much of a hassle, let me know and I can see about sending you a wheel for python 3.6 (we don’t build these wheels by default at the moment).

Thank you for the answer.
However, after installation, I get an error.
The figure below shows the execution error after the installation process.strong text

:\Users\Kim>pip3 install natcap.invest
Requirement already satisfied: natcap.invest in c:\anaconda3\lib\site-packages (3.7.0)
Requirement already satisfied: chardet>=3.0.4 in c:\anaconda3\lib\site-packages (from natcap.invest) (3.0.4)
Requirement already satisfied: psutil<5.6.0 in c:\anaconda3\lib\site-packages (from natcap.invest) (5.4.7)
Requirement already satisfied: taskgraph[niced_processes]>=0.8.2 in c:\anaconda3\lib\site-packages (from natcap.invest) (0.8.3)
Requirement already satisfied: xlrd>=1.2.0 in c:\anaconda3\lib\site-packages (from natcap.invest) (1.2.0)
Requirement already satisfied: GDAL<3.0,>=2.0 in c:\anaconda3\lib\site-packages (from natcap.invest) (2.3.3)
Requirement already satisfied: Rtree>=0.8.2 in c:\anaconda3\lib\site-packages (from natcap.invest) (0.8.3)
Requirement already satisfied: Pyro4==4.41 in c:\anaconda3\lib\site-packages (from natcap.invest) (4.41)
Requirement already satisfied: scipy>=0.16.1 in c:\anaconda3\lib\site-packages (from natcap.invest) (1.1.0)
Requirement already satisfied: six in c:\anaconda3\lib\site-packages (from natcap.invest) (1.11.0)
Requirement already satisfied: pygeoprocessing>=1.6.1 in c:\anaconda3\lib\site-packages (from natcap.invest) (1.7.0)
Requirement already satisfied: matplotlib in c:\anaconda3\lib\site-packages (from natcap.invest) (3.1.1)
Requirement already satisfied: pandas>=0.22.0 in c:\anaconda3\lib\site-packages (from natcap.invest) (0.25.1)
Requirement already satisfied: numpy!=1.16.0,>=1.11.0 in c:\anaconda3\lib\site-packages (from natcap.invest) (1.15.4)
Requirement already satisfied: Shapely>=1.6.4 in c:\anaconda3\lib\site-packages (from natcap.invest) (1.6.4.post1)
Requirement already satisfied: setuptools in c:\anaconda3\lib\site-packages (from Rtree>=0.8.2->natcap.invest) (41.0.1)
Requirement already satisfied: serpent>=1.11 in c:\anaconda3\lib\site-packages (from Pyro4==4.41->natcap.invest) (1.28)
Requirement already satisfied: future in c:\anaconda3\lib\site-packages (from pygeoprocessing>=1.6.1->natcap.invest) (0.17.1)
Requirement already satisfied: Cython in c:\anaconda3\lib\site-packages (from pygeoprocessing>=1.6.1->natcap.invest) (0.28.5)
Requirement already satisfied: cycler>=0.10 in c:\anaconda3\lib\site-packages (from matplotlib->natcap.invest) (0.10.0)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\anaconda3\lib\site-packages (from matplotlib->natcap.invest) (1.0.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in c:\anaconda3\lib\site-packages (from matplotlib->natcap.invest) (2.2.0)
Requirement already satisfied: python-dateutil>=2.1 in c:\anaconda3\lib\site-packages (from matplotlib->natcap.invest) (2.7.3)
Requirement already satisfied: pytz>=2017.2 in c:\anaconda3\lib\site-packages (from pandas>=0.22.0->natcap.invest) (2018.5)

C:\Users\Kim>invest --h
Traceback (most recent call last):
File “c:\anaconda3\lib\runpy.py”, line 193, in run_module_as_main
“main”, mod_spec)
File “c:\anaconda3\lib\runpy.py”, line 85, in run_code
exec(code, run_globals)
File "C:\Anaconda3\Scripts\invest.exe_main
.py", line 5, in
File "c:\anaconda3\lib\site-packages\natcap\invest_init
.py", line 8, in
import pygeoprocessing
File “c:\anaconda3\lib\site-packages\pygeoprocessing_init_.py”, line 12, in
from . import geoprocessing
File “c:\anaconda3\lib\site-packages\pygeoprocessing\geoprocessing.py”, line 6, in
from .geoprocessing_core import DEFAULT_GTIFF_CREATION_OPTIONS
File “src\pygeoprocessing\geoprocessing_core.pyx”, line 20, in init pygeoprocessing.geoprocessing_core
File “c:\anaconda3\lib\site-packages\osgeo_init_.py”, line 26, in
gdal = swig_import_helper()
File "c:\anaconda3\lib\site-packages\osgeo_init
.py", line 22, in swig_import_helper
_mod = imp.load_module(’_gdal’, fp, pathname, description)
File “c:\anaconda3\lib\imp.py”, line 243, in load_module
return load_dynamic(name, filename, file)
File “c:\anaconda3\lib\imp.py”, line 343, in load_dynamic
return _load(spec)
ImportError: DLL load failed: The specified procedure could not be found.

C:\Users\Kim>C:\Users\Kim\AppData\Local\Programs\Python\Python37\python.exe d:\Habitat.py
Traceback (most recent call last):
File “d:\Habitat.py”, line 6, in
import natcap.invest.habitat_quality
ModuleNotFoundError: No module named ‘natcap’
-=------------------------------------------------------------------------------------------------------------------------------------------

Well, there are a couple things that come to mind.

This error

 ImportError: DLL load failed: The specified procedure could not be found.

is related to your gdal installation. I can see from your pip install log that gdal is already installed to your conda environment, so something is happening that is preventing natcap.invest from importing gdal. Are you able to open a python shell and from osgeo import gdal? If not, then there’s an issue with your gdal installation that you’ll need to debug.

This error

ModuleNotFoundError: No module named ‘natcap’

Looks different to me because it can’t find natcap.invest at all. It looks like you’re trying to use a different python, though, one installed at C:\Users\Kim\AppData\Local\Programs\Python\Python37\python.exe. Since you’ve already installed everything to your conda python installation, you’ll need to use that. It should be somewhere within C:\Anaconda3.

Let us know how this goes!
James

1 Like

I have been running Invest Hydropower Water Yield and I have been having the same problem.

ModuleNotFoundError: No module named ‘natcap’

My python version is:

Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

natcap.invest installed is 3.8.6 (natcap.invest-3.8.6-cp37-cp37m-win_amd64.whl) as you can see in the list below.

Package Version


chardet 3.0.4
Cython 0.29.21
future 0.18.2
GDAL 2.4.1
natcap.invest 3.8.6
numpy 1.19.1
pandas 1.1.1
pip 20.1.1
psutil 5.7.2
pygeoprocessing 1.9.2
Pyro4 4.77
python-dateutil 2.8.1
pytz 2020.1
retrying 1.3.3
Rtree 0.9.4
scipy 1.4.1
serpent 1.30.2
setuptools 47.1.0
Shapely 1.6.4.post2
six 1.15.0
taskgraph 0.10.0
wheel 0.35.1
xlrd 1.2.0
xlwt 1.3.0

My windows is 64 bit.

Does some could help me? Many thanks!

Hey @Luciene welcome to the forums! I see that you posted the same question over on ModuleNotFoundError: No module named 'natcap', so I’ll close this thread and write back more fully over on the other thread.

2 Likes