setup.py中的替代依赖项(回退) [英] Alternative dependencies (fall back) in setup.py

查看:64
本文介绍了setup.py中的替代依赖项(回退)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我要安装pyodbc.它不能在某些Windows机器上构建,但是还有一种选择-pypyodbc,它是pyobdc的纯python实现.

Say I want to install pyodbc. It can't be build on some Windows machines but there's an alternative - pypyodbc which is pure python implementation of pyobdc.

是否有一种方法可以为setuptools.setup指定install_requires=["pyobdc"]并在未安装前一个软件包的情况下退回到pypyodbc?

Is there a way to specify install_requires=["pyobdc"] for setuptools.setup with falling back to pypyodbc if the former package wasn't installed?

UPD:针对这种情况的解决方案:

UPD: My solution for this particular situation:

import sys
from setuptools import setup

if sys.platform.startswith("win"):
    pyodbc = "pypyodbc>=1.2.0"
else:
    pyodbc = "pyodbc>=3.0.7"

...

setup(
      ...
      install_requires=[pyobdc]
      )

但是我仍然在寻找更通用的解决方案.

But I still look for a more general solution.

推荐答案

做你已经在做的事情似乎是一个常见的建议,但是由于这个问题是此类问题在Google网站上的热门话题,因此我要指出install_requires支持在 PEP 508 中指定的相当复杂的迷你语言. :

Doing what you are already doing seems like a common recommendation, but since this question is the top google hit for this sort of question, I'll point out that install_requires supports a fairly intricate mini-language which is specified in PEP 508:

install_requires = [
    'pypyodbc>=1.2.0;platform_system=="Windows"',
    'pyodbc>=3.0.7;platform_system!="Windows"'
]

在对相关问题的评论中,用户

In a comment to a related question, user Marius Gedminas notes that having your install_requires computed in code could have some adverse effects, so the above should be preferred to avoid that problem.

(另一方面, https://hynek.me/articles/conditional-python -dependencies/如果您必须支持setuptools的旧版本,则会对一些非常严重的可移植性问题感到遗憾.)

(On the other hand, https://hynek.me/articles/conditional-python-dependencies/ laments some pretty serious portability problems if you have to support old versions of setuptools.)

这篇关于setup.py中的替代依赖项(回退)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆