Error while running InVEST in Python enviroment

Dear all, 
I am trying to run InVEST in Python but I got the message as the follows: 

C:\Users\vuong>C:\Python27\python.exe D:\InVEST\WaY\WAY.py
Traceback (most recent call last):
  File "D:\InVEST\WaY\WAY.py", line 6, in <module>
    import natcap.invest.hydropower.hydropower_water_yield
  File "C:\Python27\lib\site-packages\natcap\invest\__init__.py", line 8, in <module>
    import pygeoprocessing
  File "C:\Python27\lib\site-packages\pygeoprocessing\__init__.py", line 12, in <module>
    from . import geoprocessing
  File "C:\Python27\lib\site-packages\pygeoprocessing\geoprocessing.py", line 46, in <module>
    import rtree
  File "C:\Python27\lib\site-packages\rtree\__init__.py", line 1, in <module>
    from .index import Rtree
  File "C:\Python27\lib\site-packages\rtree\index.py", line 5, in <module>
    from . import core
  File "C:\Python27\lib\site-packages\rtree\core.py", line 116, in <module>
    raise OSError("could not find or load spatialindex_c.dll")
OSError: could not find or load spatialindex_c.dll

I tried to fix it by reinstall rtree package again, but it did not work. Do you have any idea how to solve it. 
Thank you in advance.
Ps, I am using Window 10 64 bits, InVEST 3.4.4, Python 2.7.12 and the attachment is my script.

Comments

  • jdouglassjdouglass Administrator, NatCap Staff
    Hello,
    Rtree depends on the C++ library libspatialindex, which unfortunately isn't shipped with any of the distributions on PyPI.  Could you try out the Rtree binary from https://www.lfd.uci.edu/~gohlke/pythonlibs/#rtree and see if that fixes the issue?  The wheels available on that site include all of the necessary dlls for each respective package.  Installing the file would be a matter of pip installing the downloaded file.

    Hope this helps!
    James
  • Hi, 
    Thank for your quick response. I did try this option but it did not work. I have tried to find the solutions online and until now I could not fix. 
    I could run the Stand alone version of INVEST, but I need to run many simulations with different scenarios, thus I turn to use Python instead to speed up my work. 
    Thus, I would ask if is there any way I can take the configuration or packages from the set up of the Stand alone version and bring it to Python (Just thinking because I am a beginner of Python).
    Bests,
  • jdouglassjdouglass Administrator, NatCap Staff
    Running lots of simulations in sequence is a great reason to use the python API, but it does take a little work to get everything set up.  There isn't currently any way to just use the standalone's binaries from the python API.

    When you say that installing the wheel from Gohlke's python builds didn't work, what was the error presented?  Getting rtree installed via this method is one of the easiest ways to make sure that libspatialindex is available on your windows system.


  • Somehow the errors with Rtree disappear but the new errors are comming
    C:\Users\vuong>C:\Python27\python.exe D:\InVEST\WaY\WAY.py
    Traceback (most recent call last):
      File "D:\InVEST\WaY\WAY.py", line 6, in <module>
        import natcap.invest.hydropower.hydropower_water_yield
      File "C:\Python27\lib\site-packages\natcap\invest\__init__.py", line 8, in <module>
        import pygeoprocessing
      File "C:\Python27\lib\site-packages\pygeoprocessing\__init__.py", line 12, in <module>
        from . import geoprocessing
      File "C:\Python27\lib\site-packages\pygeoprocessing\geoprocessing.py", line 49, in <module>
        import scipy.interpolate
      File "C:\Python27\lib\site-packages\scipy\interpolate\__init__.py", line 158, in <module>
        from .interpolate import *
      File "C:\Python27\lib\site-packages\scipy\interpolate\interpolate.py", line 11, in <module>
        import scipy.linalg
      File "C:\Python27\lib\site-packages\scipy\linalg\__init__.py", line 174, in <module>
        from .misc import *
      File "C:\Python27\lib\site-packages\scipy\linalg\misc.py", line 5, in <module>
        from .blas import get_blas_funcs
      File "C:\Python27\lib\site-packages\scipy\linalg\blas.py", line 155, in <module>
        from scipy.linalg import _fblas
    ImportError: DLL load failed: The specified module could not be found.

    I tried the same way to solve the problem, i.e. downloading the scipy from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal and install it. But this time, it does not work. 
    Do you have any idea how to deal with scipy???
    I am thinking to  try a Linux Virtual Machine with Virtualbox then install InVEST in that machine. 
    Does InVEST works better in Linux (Python version).
    Thanks,
  • jdouglassjdouglass Administrator, NatCap Staff
    When installing a new version of a package, it usually helps to pip uninstall the package before pip installing it.  This will make sure that the new build of the package you want to install is installed as expected.

    In the case of scipy, did you also install the gohlke build of numpy from the same site?

    InVEST should work fine on linux, and there are instructions at https://invest.readthedocs.io/en/latest/installing.html for what's needed.

    Let us know how it goes!
  • Thank you for your useful tip. I followed your advice and install again. It seems work but it give me this error: 
    C:\Users\vuong>C:\Python27\python.exe D:\InVEST\WaY\WAY.py
    Traceback (most recent call last):
      File "D:\InVEST\WaY\WAY.py", line 25, in <module>
        natcap.invest.hydropower.hydropower_water_yield.execute(args)
      File "C:\Python27\lib\site-packages\natcap\invest\hydropower\hydropower_water_yield.py", line 458, in execute
        (rast_uri, 1), sheds_uri, 'ws_id', ignore_nodata=False)
      File "C:\Python27\lib\site-packages\pygeoprocessing\geoprocessing.py", line 1160, in zonal_statistics
        aggregate_layer_name, aggregate_vector_path))
    RuntimeError: Could not open layer ws_id on D:/InVEST/NDR/CAL/basin_cal_vector/basin_cal_wquality1.shp
    I checked the shapefile again. It contained a column named ws_id as the requirement of the module, but I dont know why it give me this error. 
    Do you have any idea/solution? 
    Thank you very much,


  • jdouglassjdouglass Administrator, NatCap Staff
    The error is saying that the filepath given (' D:/InVEST/NDR/CAL/basin_cal_vector/basin_cal_wquality1.shp') could not be opened.  Usually this is because the path is *slightly* misspelled or the file is in the wrong folder.
  • Thank you. I made a shorter path and rename the file as "ws_id.shp", then it worked but still have other error like: 
    C:\Users\vuong>python D:\InVEST\WaY\WAY.py
    Traceback (most recent call last):
      File "D:\InVEST\WaY\WAY.py", line 26, in <module>
        natcap.invest.hydropower.hydropower_water_yield.execute(args)
      File "C:\Python27\lib\site-packages\natcap\invest\hydropower\hydropower_water_yield.py", line 462, in execute
        watershed_results_uri, ws_stats_dict, key_name, 'ws_id', 'mean')
      File "C:\Python27\lib\site-packages\natcap\invest\hydropower\hydropower_water_yield.py", line 906, in _add_zonal_stats_dict_to_shape
        stats_map[ws_val]['sum']) / stats_map[ws_val]['count']
    KeyError: 13

    I checked for other modules: 
    - The NDR worked very well and the results are the same with what I got from the GUI version (without changing the path of the watershed layer)
    - The SDR module gave me error as the following one.
    C:\Users\vuong>python D:\InVEST\WaY\SDR.py
    Traceback (most recent call last):
      File "D:\InVEST\WaY\SDR.py", line 25, in <module>
        natcap.invest.sdr.execute(args)
      File "C:\Python27\lib\site-packages\natcap\invest\sdr.py", line 183, in execute
        f_reg['flow_direction_path'], f_reg['ls_path'])
      File "C:\Python27\lib\site-packages\natcap\invest\sdr.py", line 334, in _calculate_ls_factor
        cell_size = flow_accumulation_info['mean_pixel_size']
    KeyError: 'mean_pixel_size'

    Thank you again and sorry for posting lots of errors.
  • DaveDave Member, Administrator, NatCap Staff
    For your Hydropwer Water Yield error, please follow this thread where the same error is reported: 



Sign In or Register to comment.