[gdal-dev] GDAL version in pip requirements file

Luca Delucchi lucadeluge at gmail.com
Thu Sep 28 07:56:14 PDT 2023


Hi Peter,

Il mar 26 set 2023, 16:33 Peter Schmitt <pschmitt at gmail.com> ha scritto:

> 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:
>

Thanks for your help but I'm looking something strictly related to
requirements.txt

>
> 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
>         ''',
> )
>

Best
Luca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230928/e886aeff/attachment.htm>


More information about the gdal-dev mailing list