python - 在 setup.py 要求中提供 pytz 版本

标签 python distutils setup.py pytz

问题

我想在我的库的 setup.py 脚本中包含对 pytz 的要求,但还想设置所需的最低版本。但是 pytz 模块使用的版本号(例如“2012f”)似乎与 distutils 想要提供的版本不兼容(例如。 "1.1.3").

有没有办法在不改变 pytz 的情况下包含对特定版本 pytz 的要求(例如 >=2012f) distutils?

详情

为此,我在 setup.py 文件中做了类似的事情:

setup(
    # ... basic data here ...
    requires=[
        'pytz (>=2012f)',
    ],
    # ... some other data here ...
)

但是当我在做sudo python setup.py install时,出现了如下错误:

Traceback (most recent call last):
  File "setup.py", line 25, in <module>
    long_description=long_description,
  File "/usr/lib/python2.7/distutils/core.py", line 112, in setup
    _setup_distribution = dist = klass(attrs)
  File "/usr/lib/python2.7/distutils/dist.py", line 259, in __init__
    getattr(self.metadata, "set_" + key)(val)
  File "/usr/lib/python2.7/distutils/dist.py", line 1220, in set_requires
    distutils.versionpredicate.VersionPredicate(v)
  File "/usr/lib/python2.7/distutils/versionpredicate.py", line 115, in __init__
    self.pred = [splitUp(aPred) for aPred in str.split(",")]
  File "/usr/lib/python2.7/distutils/versionpredicate.py", line 25, in splitUp
    return (comp, distutils.version.StrictVersion(verStr))
  File "/usr/lib/python2.7/distutils/version.py", line 40, in __init__
    self.parse(vstring)
  File "/usr/lib/python2.7/distutils/version.py", line 107, in parse
    raise ValueError, "invalid version number '%s'" % vstring
ValueError: invalid version number '2012f'

问题似乎是由 distutils 试图匹配这个正则表达式引起的:

version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
                        re.VERBOSE)

当不匹配时,会引发上述错误。

我看到有人更改了 pytz 的源代码(将版本更改为更像 2012.6 的版本),但这对我来说是个非常糟糕的主意。我希望我错过了另一种方式。

pytz (>=2012f) 更改为 pytz 可以,但它不会将要求限制为特定版本的 pytz 模块。

最佳答案

使用 install_requires setuptools option :

setup(
    # ... basic data here ...
    install_requires='pytz>=2012f', # distutils ignores it with a warning, pip uses it
    # ... some other data here ...
)

关于python - 在 setup.py 要求中提供 pytz 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12926052/

相关文章:

python - fatal error : Python. h:没有这样的文件或目录 - 未使用 python-devel 解决

python - 无法使用for循环更改矩阵的值

python - 替换分发版 python 脚本中的符号

Python3 共享扩展不链接库依赖

python - PyTorch DataLoader 将批处理作为列表返回,并将批处理作为唯一条目。从我的 DataLoader 获取张量的最佳方法是什么

python - 将文本(字符串)插入elasticsearch时出错

python - 除非导入,否则 distutils.spawn 不可用

c++ - Linux下使用distutils交叉编译python扩展

python - setup.py:在尝试安装之前需要最新版本的 setuptools

python - load_entry_point 看不到其他模块 - "No module named"错误