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