Getting Invest working in python

I have really struggled with getting this running (taken me 3 effing days!). So I thought I would share the love, in case it is helpful to others!

What is in Invest?

Invest is an ecosystem services model developed by the natural capital project and can by installed here. I’m working on the pollinator ecosystem services one at the moment…

Why run it in python?

Once you get the code working in python, it is possible to run multiple combinations of parameters for sensitivity analysis. Yay!

What’s the issue?

Installing python libraries such as gdal, numpy and scipy is a pain! Especially when you have multiple versions of python, and different versions are linked to different programs such as ArcGIS and InVEST etc… So a massive pain in the posterior associated (to make a long story short).

31

What can you do?

The easiest and quickest workaround for getting it working is to install Anaconda, which is python with lots of libraries built in – saves a lot of hassle!

Basically I have been following this great page, which shows you how to get it running in python , but without much success installing all the python libraries. To get started, click on the link. I’m going to go through the “Installation steps”, but using anaconda instead of python, which got things working for me. The subsequent steps should then work.

1.Install ANACONDA

This can be done from here https://www.continuum.io/downloads.Make sure you download win 32 bit python 2.7 for it to work on invest. Also make sure to tick the box which sets it to the default path for python while you are installing it.

2. Install the latest invest_natcap library from http://data.naturalcapitalproject.org/nightly-build/release_default/?C=M;O=D

3. Install GDAL as follows:

Go into the start menu>all programs>anaconda2(32 bit)>Anaconda prompt

type: conda install -c https://conda.anaconda.org/osgeo gdal

say “y” when prompted

then type: conda install gdal

again with a “y” if prompted

4. Then download .whl files for shapely and pygeoprocessing from here http://www.lfd.uci.edu/~gohlke/pythonlibs/ (just use CTR+F to find them). Make sure they are for python 27 and win32

5. Use the anaconda cmd (start menu>all programs>anaconda2(32 bit)>Anaconda prompt) and navigate to the folder where the wheel (whl) files were saved. This can be done using the cd command (example: cd C:\Anaconda2)

Then it is possible to use pip, like in python, to install shapely and pygeoprocessing:

type: Pip install shapely

By pressing tab after spelling shapely, it will take you the whl file starting with shapely. Once the file has been found, press enter.

Do the same with pygeoprocessing (pip install pygeoprocessing)

Now it should be possible to to continue to the “Running python scripts” on this page and get the batch files running!

Happy times…I hope this helps!

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s