InVEST python package installation error from source on Linux OS

Hello,

I am currently trying to install InVEST from source on my Ubuntu 20.04LTS with a Linux operating system and have followed the directions here: Installing InVEST From Source β€” InVEST 3.9.0.post122+g00b6c6e7 documentation

However, I ran both pip and Conda commands and am still not able to install InVEST. After running pip natcap.invest the installation fails with the GDAL dependency.

Here is a part of my error message:
ERROR: Command errored out with exit status 1: /home/username/software-tools/anaconda3/envs/Python37/bin/python -u -c β€˜import sys, setuptools, tokenize; sys.argv[0] = β€˜"’"’/tmp/pip-install-vq1fhgi6/gdal_c5836a2f273c4c4ab26554c66a794416/setup.py’"’"’; file=’"’"’/tmp/pip-install-vq1fhgi6/gdal_c5836a2f273c4c4ab26554c66a794416/setup.py’"’"’;f=getattr(tokenize, β€˜"’"β€˜open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, β€˜"’"’\n’"’"’);f.close();exec(compile(code, file, β€˜"’"β€˜exec’"’"’))’ install --record /tmp/pip-record-3y_dmg70/install-record.txt --single-version-externally-managed --compile --install-headers /home/username/software-tools/anaconda3/envs/Python37/include/python3.7m/GDAL Check the logs for full command output.

Thanks for your help in advance,

Rachel

Hi @rxchelzhxng ,

It can certainly be a pain to get set up with an InVEST development environment. We recommend using miniconda to setup environments via the command line: https://docs.conda.io/en/latest/miniconda.html

With conda setup you can create a new conda environment:

conda create -p ./my-new-env python=3.8

Then we can activate that environment:

conda activate ./my-new-env

From there we can install our dependencies:

conda install gdal rtree shapely numpy cython

Then we should be able to grab InVEST from pip

pip install natcap.invest

Hopefully this helps get you set up! Let us know what other issues come up and we can step through them.

Cheers,

Doug

Hi Doug,

Thanks for the prompt reply. I’ve tried the recommended commands and once I run the last command using pip for the install of InVEST, I get the error message:

ERROR: Command errored out with exit status 1: /home/username/Desktop/Korotu/Korotu_Drafts/TESTNATCAP/bin/python -u -c β€˜import sys, setuptools, tokenize; sys.argv[0] = β€˜"’"’/tmp/pip-install-98hxz40_/gdal_50e6798712d143f79e51100ca63cf1f5/setup.py’"’"’; file=’"’"’/tmp/pip-install-98hxz40_/gdal_50e6798712d143f79e51100ca63cf1f5/setup.py’"’"’;f=getattr(tokenize, β€˜"’"β€˜open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, β€˜"’"’\n’"’"’);f.close();exec(compile(code, file, β€˜"’"β€˜exec’"’"’))’ install --record /tmp/pip-record-zxbvmwev/install-record.txt --single-version-externally-managed --compile --install-headers /home/username/Desktop/Korotu/Korotu_Drafts/TESTNATCAP/include/python3.8/GDAL Check the logs for full command output.

I believe the error is still the same as before with installing GDAL

Thanks for the help,

Rachel

Could you do a quick gdalinfo --version within your activated conda environment and let us know which GDAL version is installed?

InVEST expects a specific version of GDAL, and if it can’t find it, pip install will attempt to build it from source, which is probably what we’re seeing here.

In case this is what’s happening, could you try this?

conda install -c conda-forge gdal rtree shapely numpy cython

The -c conda-forge should pull a more recent version of GDAL than what’s in the default conda channel.

James

1 Like

Hi James,

I tried the command

gdalinfo --version

and it doesn’t seem to work on my conda environment. However, I do know that the current version of GDAL I have installed is 3.0.2. After trying to run the command
conda install -c conda-forge gdal rtree shapely numpy cython
and
pip install natcap.invest

I get the same error as before: ERROR: Command errored out with exit status 1: /home/username/Desktop/Korotu/Korotu_Drafts/TESTNATCAP/bin/python -u -c β€˜import sys, setuptools, tokenize; sys.argv[0] = β€˜"’"’/tmp/pip-install-98hxz40_/gdal_50e6798712d143f79e51100ca63cf1f5/setup.py’"’"’; file =’"’"’/tmp/pip-install-98hxz40_/gdal_50e6798712d143f79e51100ca63cf1f5/setup.py’"’"’;f=getattr(tokenize, β€˜"’"β€˜open’"’"’, open)( file );code=f.read().replace(’"’"’\r\n’"’"’, β€˜"’"’\n’"’"’);f.close();exec(compile(code, file , β€˜"’"β€˜exec’"’"’))’ install --record /tmp/pip-record-zxbvmwev/install-record.txt --single-version-externally-managed --compile --install-headers /home/username/Desktop/Korotu/Korotu_Drafts/TESTNATCAP/include/python3.8/GDAL Check the logs for full command output.

As a side note, I noticed that as I was trying to install GDAL within my conda environment, it does not support Python version 3.9. However, it does support python version 3.8 and 3.7

Ah, that’ll be the issue, then. InVEST requires GDAL >= 3.1.2, so when pip can’t find a version of GDAL matching the requirement, it tries to install it locally.

That’s correct, though I’m sure GDAL will update their conda packages in due time. But it’s also worth noting that InVEST is only currently tested against python 3.7 and 3.8. Could you try downgrading your conda environment python to 3.8 and reinstalling?

Let us know how this goes!
James

1 Like

Thanks for the recommendation James!

I solved the issue by running the following commands with my Linux OS and a Python 3.9.1 conda environment

conda create -p
conda activate
conda config --add channels conda-forge
conda config --set channel_priority strict # Note did not seem to do anything
conda install β€œgdal>=3.1.2” rtree shapely numpy cython scipy
pip install natcap.invest

(Although I still haven’t tested any of the models yet, this is only the install)

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.