[gdal-dev] GDAL version in pip requirements file

Peter Schmitt pschmitt at gmail.com
Tue Sep 26 07:33:37 PDT 2023


I know you mention requirements.txt, but I write my setup.py with a
function that uses gdal-config to get Python bindings for the version of
GDAL I have installed.  It looks something like this:

from setuptools import setup, find_packages
from subprocess import check_output

class GdalNotFoundError(Exception): pass

def gdal_version():
    """Returns version provided by gdal-config

    >>> gdal_version()
    '3.3.1'
    """

    try:
        version = check_output(['gdal-config', '--version'])
    except FileNotFoundError as err:
        raise GdalNotFoundError('GDAL must be installed and `gdal-config`
must be in the $PATH to continue')

    return version.decode('utf-8').strip()

setup(
    name='foo',
    description='bar.',
    version='0.0.0',
    py_modules=['cli'],
    packages=find_packages(exclude=['tests', 'docs']),
    include_package_data=True,
    install_requires=[
        f'gdal=={gdal_version()}',
    ],
    entry_points='''
        [console_scripts]
        foo=cli:cli
        ''',
)

On Tue, Sep 26, 2023 at 1:13 AM Stefan Blumentrath via gdal-dev <
gdal-dev at lists.osgeo.org> wrote:

> Hi Luca,
>
> You could parse the gdal config version output into an environment
> variable and then specify the version in requirements.txt like this:
> GDAL==${GDAL_VERSION}
>
> Cheers,
> Stefan
> On 26/09/2023, 08:55 Luca Delucchi via gdal-dev <gdal-dev at lists.osgeo.org>
> wrote:
>
>> Hi everyone,
>>
>> I would like to know if it is possible to set GDAL version in the pip
>> requirements file using gdal-config of the machine running the
>> installation, I tried some different ways but I was not able to do it,
>> also leaving GDAL without any specified version doesn't work because
>> it takes the last python GDAL version available in that system.
>>
>> Do you have any advice?
>>
>>
>> --
>> ciao
>> Luca
>>
>> www.lucadelu.org
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>


-- 
Pete
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230926/e0969173/attachment.htm>


More information about the gdal-dev mailing list