PatBall1 / detectree2

Python package for automatic tree crown delineation based on the Detectron2 implementation of Mask R-CNN
https://patball1.github.io/detectree2/
MIT License
148 stars 35 forks source link

Failure to install on 64-bit Windows 10 system, and Python version 3.8.10 #92

Open richiy opened 1 year ago

richiy commented 1 year ago

Collecting rasterio==1.3a3 Using cached rasterio-1.3a3.tar.gz (401 kB) Installing build dependencies ... done Getting requirements to build wheel ... error ERROR: Command errored out with exit status 1: command: 'C:\Users\xxxx\AppData\Local\Programs\Python\Python38\python.exe' 'C:\Users\xxxx\AppData\Local\Programs\Python\Python38\lib\site-packages\pip_vendor\pep517\in_process_in_process.py' get_requires_for_build_wheel 'C:\Users\xxxx\AppData\Local\Temp\tmprw8grws6' cwd: C:\Users\xxxx\AppData\Local\Temp\pip-install-ozyk4_bv\rasterio_97d0b87c61a740218c42e09690312378 Complete output (2 lines): INFO:root:Building on Windows requires extra options to setup.py to locate needed GDAL files. More information is available in the README. ERROR: A GDAL API version must be specified. Provide a path to gdal-config using a GDAL_CONFIG environment variable or use a GDAL_VERSION environment variable.

PatBall1 commented 1 year ago

@richiy would you please provide some details on your system/setup?

For now, detectree2 has only been tested on Linux and in Colab notebooks so we would recommend either of those if available to you.

richiy commented 1 year ago

Ok,thanks!
I am using a 64-bit Windows 10 system, and Python version 3.8.10 in 64-bit.

PatBall1 commented 1 year ago

Installing on windows can be a bit tricky. Try

  1. Install GDAL:

GDAL (Geospatial Data Abstraction Library) is a translator library for raster and vector geospatial data formats and is necessary for rasterio to function. You can install it with conda, an open-source package management system and environment management system.

conda install -c conda-forge gdal

If you are not using Anaconda, you can download precompiled binaries for GDAL from GIS Internals.

  1. Set GDAL environment variables:

After GDAL is installed, you need to add GDAL to your system's PATH and set the GDAL_CONFIG environment variable. This variable should point to the gdal-config script that was installed with GDAL.

The GDAL installation path will likely be something like C:\Program Files\GDAL. You should add C:\Program Files\GDAL to your PATH and set GDAL_CONFIG=C:\Program Files\GDAL\gdal-config.

If you can't find gdal-config (which can happen with some installations), then try setting the GDAL_VERSION environment variable to the version of GDAL you installed (like GDAL_VERSION=2.2.3).

You can set these variables in the "Environment Variables" section of your system settings on Windows, or you can set them in your shell before running pip:

set GDAL_CONFIG=C:\Program Files\GDAL\gdal-config
set GDAL_VERSION=2.2.3
pip install rasterio

Try installing rasterio with conda:

Since rasterio and GDAL can be tricky to install with pip on Windows, an easier option might be to just install rasterio with conda, which will also automatically handle the GDAL dependency:

conda install -c conda-forge rasterio

Please ensure that you replace the paths in the solutions above with the correct paths from your local system

jvanpassel commented 7 months ago

Hi, I had the same issue on a Windows computer with Python version 3.10, but following these steps got me past this first error. However, now I get the following new errors during the installation of detectree2:

rasterio/_base.c(768): fatal error C1083: Cannot open include file: 'cpl_conv.h': No such file or directory error: command 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX86\x64\cl.exe' failed with exit code 2 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for rasterio

error: could not create 'build\temp.win-amd64-cpython-310\Release\Users\xxx\AppData\Local\Temp\pip-install-unq9wwxu\detectron2_2daef03b29624941b7c8c5c6518219d5\detectron2': The filename or extension is too long [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for detectron2

Successfully built detectree2 Failed to build rasterio detectron2 ERROR: Could not build wheels for rasterio, detectron2, which is required to install pyproject.toml-based projects

Any suggestions on how to solve this?

xabierr commented 4 months ago

I got the exact same error about rasterio but managed to build detectron2 by using:

pip install git+https://github.com/facebookresearch/detectron2.git@5aeb252b194b93dc2879b4ac34bc51a31b5aee13

I had to use: pip install rasterio though as using: conda install -c conda-forge rasterio was getting stuck at solving the environments.