最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Dynamic dependency install with pyproject.toml - Stack Overflow

programmeradmin3浏览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`

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
Add a comment  | 

1 Answer 1

Reset to default 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,
)
发布评论

评论列表(0)

  1. 暂无评论