Skip to main content
 首页 » 编程设计

python之setuptools:强制另一个包的版本(如果存在)而不强制安装这个包(如果不存在)

2024年10月01日7lhb25

在开发Pylint的过程中,我们遇到了interesting problem related to non-dependency that may break pylint package .

案例如下:

  • python-future 与 configparser 包的别名存在冲突。 Quoting official docs :

    This release removes the configparser package as an alias for ConfigParser on Py2 to improve compatibility with Lukasz Langa’s backported configparser package. Previously python-future and the configparser backport clashed, causing various compatibility issues. (Issues #118, #181)

  • python-future 本身不是 Pylint 的依赖

如果存在 python-future,强制执行 0.16 或更高限制的标准方法是什么?我想避免将依赖项定义为 future>=0.16 - 通过这样做我会强制用户安装他们不需要并且在一般情况下不会使用的包。

请您参考如下方法:

kw = {} 
try: 
    import future 
except ImportError: 
    pass 
else: 
    kw['install_requires'] = ['future>=0.16'] 
 
setup( 
    … 
    **kw 
)