ModuleNotFoundError: No module named 'natcap'

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

D:\Project_mills\hydropower_analysis_v3\python_workspace\Run>py python_script_4D007.py
Traceback (most recent call last):
File “python_script_4D007.py”, line 6, in
import natcap.invest.hydropower.hydropower_water_yield
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!

Hi @Luciene,

That does sound pretty strange! The fact that you mention that it installed just fine but then can’t be imported makes me wonder if natcap.invest is being installed to one place but then we’re using a different python to run your script.

Is it possible that you have multiple python installations on your computer? Typing where python on a cmd.exe terminal will list out all of your python installations that are on the PATH.

And also, could you tell us a little more about your python installation? Are you using a virtual environment, a conda environment, ArcGIS’s python? And also, how are you opening up your python shell?

Let us know how this goes!
James

Thank you for helping me @jdouglass!

My apologies. I am a beginner in python and natcap.invest.

When I type “where python” on “cmd.exe”:

C:\Users\lucie>where python

D:\Project_mills\hydropower_analysis_v3\python_workspace\env\Scripts\python.exe

According to that, python.exe is on the virtual environment (env folder) I created to install the python packages. All packages to run natcap.invest are on this same folder (env folder).

When I type echo %PATH%:

C:\Users\lucie>echo %PATH%

C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel® Management Engine Components\IPT;C:\Program Files\Intel\Intel® Management Engine Components\IPT;D:\Project_mills\hydropower_analysis_v3\python_workspace\env\Scripts;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel® Management Engine Components\DAL;C:\Program Files\Intel\Intel® Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel® Management Engine Components\IPT;C:\Program Files\Intel\Intel® Management Engine Components\IPT;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\Users\lucie\AppData\Local\Programs\Python\Python37\Scr

The last line shows where python 3.7 was installed (C:\Users\lucie\AppData\Local\Programs\Python\Python37\Scr)

I also have Arcgis 10.6.1 with python 2.7.14, see below:

print(sys.version)

print(matplotlib.version)

print(numpy.version)

print(scipy.version)

2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 20:19:30) [MSC v.1500 32 bit (Intel)]

1.5.2

1.9.3

0.17.0

** I am open my python shell using Atom (https://atom.io/) **

Do you have any suggestion? Thanks!

When I used Windows PowerShell to run the script, other error came to the light. See:

PS C:\Users\lucie> D:\Project_mills\hydropower_analysis_v3\python_workspace\env\Scripts\python.exe D:\Project_mills\hydropower_analysis_v3\python_workspace\Run\python_script_4D007.py
Traceback (most recent call last):
File “D:\Project_mills\hydropower_analysis_v3\python_workspace\Run\python_script_4D007.py”, line 6, in
import natcap.invest.hydropower.hydropower_water_yield
File “D:\Project_mills\hydropower_analysis_v3\python_workspace\env\lib\site-packages\natcap\invest_init_.py”, line 8, in
import pygeoprocessing
File “D:\Project_mills\hydropower_analysis_v3\python_workspace\env\lib\site-packages\pygeoprocessing_init_.py”, line 13, in
from . import geoprocessing
File “D:\Project_mills\hydropower_analysis_v3\python_workspace\env\lib\site-packages\pygeoprocessing\geoprocessing.py”, line 48, in
import scipy.interpolate
File “D:\Project_mills\hydropower_analysis_v3\python_workspace\env\lib\site-packages\scipy\interpolate_init_.py”, line 167, in
from .interpolate import *
File “D:\Project_mills\hydropower_analysis_v3\python_workspace\env\lib\site-packages\scipy\interpolate\interpolate.py”, line 15, in
import scipy.special as spec
File “D:\Project_mills\hydropower_analysis_v3\python_workspace\env\lib\site-packages\scipy\special_init_.py”, line 634, in
from . import _ufuncs
ImportError: DLL load failed: The specified module could not be found.
PS C:\Users\lucie>

Each python shell will need to be individually activated in order to access the natcap.invest package that you have installed to the virtual environment at D:\Project_mills\hydropower_analysis_v3\python_workspace\env.

So since you are accessing a python shell through atom, you’ll need to activate your virtual environment from within atom if you’d like that python shell to access the packages installed in that env. You can verify which python is being used (like whether python is within the virtual environment) by checking sys.executable.

In the case of powershell, it looks like you’ve already activated your virtual environment, so there’s something else going on here. FWIW I haven’t had great success running virtualenv-based virtual environments through powershell, but I haven’t looked into it a whole lot.

Let us know what you find out!
James

1 Like