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
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
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.