Skip to content

Python bindings to gdal should make use of extras feature for packaging. #2158

@rdenham

Description

@rdenham

Expected behavior and actual behavior.

numpy is an optional package for the python gdal bindings. It would be nice if we could make use of the extras feature when packaging, so that you could have something like

gdal[numpy]

in a requirements.txt file.
Otherwise, the order of the packages you install becomes important, leading to problems like those encountered by users as described here and here.

Steps to reproduce the problem.

If you install gdal followed by numpy then you don't get the numpy features of gdal, and you have to work hard to correct this, e.g.,:

pip install gdal==2.4.2
pip install numpy
python -c 'from osgeo import gdal_array'
Traceback (most recent call last):
  File "/home/robert/miniconda3/envs/gdal/lib/python3.7/site-packages/osgeo/gdal_array.py", line 18, in swig_import_helper
    fp, pathname, description = imp.find_module('_gdal_array', [dirname(__file__)])
  File "/home/robert/miniconda3/envs/gdal/lib/python3.7/imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_gdal_array'

install gdal==2.4.2 
Requirement already satisfied: gdal==2.4.2 in ./miniconda3/envs/gdal/lib/python3.7/site-packages (2.4.2)

pip install --force-reinstall gdal==2.4.2 --no-cache-dir
python -c 'from osgeo import gdal_array'

What would be nice would be if you could do:

pip install gdal[numpy]==2.4.2

This current behaviour me a problem when using pip-tools, which parses a requirements.in file to produce a requirements.txt file, and one step involves an alphabetical sorting. Because gdal comes before numpy. See Issue #992

Operating system

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.3 LTS
Release:        18.04
Codename:       bionic

GDAL version and provenance

$ dpkg -l libgdal-dev
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                         Version                     Architecture                Description
+++-============================================-===========================-===========================-==============================================================================================
ii  libgdal-dev                                  2.4.2+dfsg-1~bionic0        amd64                       Geospatial Data Abstraction Library - Development files

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions