Is there a way to dynamically check the version of a package installed system wide and set that as a package dependency in the pyproject.toml? Specially, I need to check if a person already has GDAL installed system wide and if they do, set the python gdal version to that. If I were manually installing the gdal python package, I could do something like below, I just don't know if its possible to set it on the fly/dynamically in the toml.
pip install GDAL==`gdal-config --version`
Is there a way to dynamically check the version of a package installed system wide and set that as a package dependency in the pyproject.toml? Specially, I need to check if a person already has GDAL installed system wide and if they do, set the python gdal version to that. If I were manually installing the gdal python package, I could do something like below, I just don't know if its possible to set it on the fly/dynamically in the toml.
pip install GDAL==`gdal-config --version`
Share
Improve this question
asked Mar 19 at 15:44
andrewrandrewr
81515 silver badges32 bronze badges
1 Answer
Reset to default 0You can create a file called setup.py for custom installations. E.g:
import subprocess
from setuptools import setup
def get_gdal_version():
return subprocess.check_output(['gdal-config', '--version']).decode('utf-8').strip()
gdal_version = get_gdal_version()
if gdal_version:
gdal_version = f"GDAL=={gdal_version}"
install_requires = [
"some_other_package",
gdal_version if gdal_version else "GDAL",
]
setup(
name="your_project",
install_requires=install_requires,
)