简体   繁体   English

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

[英]Providing pytz version in setup.py requirements

The problem 问题

I wanted to include requirement for pytz in setup.py script in my library, but wanted also to set the minimal version required. 我想在我的库中的setup.py脚本中包含pytz要求,但是也想要设置所需的最小版本。 But the version numbers used by pytz module (eg. " 2012f ") seem to be incompatible with what distutils wants to be provided (eg. " 1.1.3 "). 但是pytz模块使用的版本号(例如“ 2012f ”)似乎与distutils想要提供的版本号不兼容(例如“ 1.1.3 ”)。

Is there any way to include requirement for specific version of pytz (eg. >=2012f ) without altering pytz or distutils ? 有没有办法在不改变pytzdistutils情况下包含特定版本的pytz (例如>=2012f )的pytz

Details 细节

To do that I did something like that in setup.py file: 为此,我在setup.py文件中做了类似的事情:

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

But when I was doing sudo python setup.py install , the following error appeared: 但是当我在做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'

Seemingly the issue is caused by distutils trying to match this regular expression: 看似问题是由试图匹配这个正则表达式的distutils引起的:

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

and when it does not match, the above error is raised. 当它不匹配时,会引发上述错误。

I have seen people altering the source code of pytz (to change the version into something more like 2012.6 ), but it looks like extremely bad idea to me. 我看到有人改变了pytz的源代码(将版本更改为更像2012.6的版本),但对我来说这看起来非常糟糕。 I hope there is another way that I missed. 我希望我错过了另一种方式。

Changing pytz (>=2012f) into pytz works, but it then does not limit the requirement to specific version of pytz module. pytz (>=2012f)更改为pytz可以正常工作,但它不会将要求限制为特定版本的pytz模块。

Using install_requires setuptools option : 使用install_requires setuptools选项

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM