<div dir="ltr"><div>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:</div><div><br></div>from setuptools import setup, find_packages<br>from subprocess import check_output<br><br>class GdalNotFoundError(Exception): pass<br><br>def gdal_version():<br>    """Returns version provided by gdal-config<br><br>    >>> gdal_version()<br>    '3.3.1'<br>    """<br><br>    try:<br>        version = check_output(['gdal-config', '--version'])<br>    except FileNotFoundError as err:<br>        raise GdalNotFoundError('GDAL must be installed and `gdal-config` must be in the $PATH to continue')<br><br>    return version.decode('utf-8').strip()<br><br>setup(<br>    name='foo',<br>    description='bar.',<br>    version='0.0.0',<br>    py_modules=['cli'],<br>    packages=find_packages(exclude=['tests', 'docs']),<br>    include_package_data=True,<br>    install_requires=[<br>        f'gdal=={gdal_version()}',<br>    ],<br>    entry_points='''<br>        [console_scripts]<br>        foo=cli:cli<br>        ''',<br>)<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 26, 2023 at 1:13 AM Stefan Blumentrath via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

 
  
  
 
 <div style="word-break:break-word"><div style="line-height:1;padding:0.5em">Hi Luca,<br><br>You could parse the gdal config version output into an environment variable and then specify the version in <a href="http://requirements.txt" target="_blank">requirements.txt</a> like this:<br>GDAL==${GDAL_VERSION}<br><br>Cheers,<br>Stefan<br></div><div style="line-height:1;padding:0.3em"><div>On 26/09/2023, 08:55 Luca Delucchi via gdal-dev <<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0.8ex 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

  Hi everyone,
  <br>
  <br> I would like to know if it is possible to set GDAL version in the pip
  <br> requirements file using gdal-config of the machine running the
  <br> installation, I tried some different ways but I was not able to do it,
  <br> also leaving GDAL without any specified version doesn't work because
  <br> it takes the last python GDAL version available in that system.
  <br>
  <br> Do you have any advice?
  <br>
  <br>
  <br> --
  <br> ciao
  <br> Luca
  <br>
  <br> <a href="http://www.lucadelu.org" target="_blank">www.lucadelu.org</a>
  <br> _______________________________________________
  <br> gdal-dev mailing list
  <br> <a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a>
  <br> <a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
  <br>
 </blockquote></div></div>

_______________________________________________<br>
gdal-dev mailing list<br>
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank">gdal-dev@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br>
</blockquote></div><br clear="all"><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Pete</div>