0

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`

1 Answer 1

0

You 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,
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.