setup.py:在尝试安装之前,需要最新版本的setuptools [英] setup.py: require a recent version of setuptools before trying to install

查看:104
本文介绍了setup.py:在尝试安装之前,需要最新版本的setuptools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个在install_requires中包含'typing;python_version<"3.5"'的程序包.显然,这种依赖性规范直到最近才实现setuptools的版本.如果用户计算机上的setuptools很旧,他们将得到:

I'm creating a package that has 'typing;python_version<"3.5"' in it's install_requires. Apparently, this kind of dependency specification has only been implemented in recent versions of setuptools. If the setuptools on the user's machine is old they'll get:

'install_requires'必须是包含有效项目/版本要求说明符的字符串或字符串列表;预期的版本规格 在; python_version<"3.5"处键入; python_version<"3.5"

'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected version spec in typing;python_version<"3.5" at ;python_version<"3.5"

简单的解决方案是告诉用户pip install my-package之前的pip install 'setuptools>=36.2.1'. (请注意,36.2.1只是我知道可以使用的版本,不一定是绝对最低要求)

The easy solution is to tell the users to pip install 'setuptools>=36.2.1' before pip install my-package. (Note that 36.2.1 is just a version that I know works, not necessarily the the absolute minimum requirement)

但是有什么方法可以在setup.py中指定此要求,以使其自动完成吗?将setuptools>=36.2.1添加到install_requiressetup_requires无效.它说Installed /tmp/pip-si2fqg-build/.eggs/setuptools-38.2.5-py3.3.egg,然后给出上面的相同错误.

But is there any way to specify this requirement in setup.py so that it gets done automatically? Adding setuptools>=36.2.1 to install_requires and setup_requires did not work. It says Installed /tmp/pip-si2fqg-build/.eggs/setuptools-38.2.5-py3.3.egg and then gives the same error above.

推荐答案

您无法一次性更新setuptools并在设置脚本中使用其代码.我看到两种可能的解决方案:如果要支持setuptools的旧版本,则不能使用env标记.使用sys.version_info:

You can't update setuptools and use its code in the setup script in one pass. I see two possible solutions: If you want to support old versions of setuptools, you can't use env markers. Implement the check yourself by using sys.version_info:

import sys
from setuptools import setup


setup(
    name='spam',
    version='0.1',
    packages=[],
    install_requires=['typing'] if sys.version_info < (3, 5) else []
)

如果您不想支持setuptools的旧版本,请检查其版本并提前中止,并通知用户:

If you don't want to support old versions of setuptools, check its version and abort early, informing the user:

import sys
from distutils.version import StrictVersion
from setuptools import setup, __version__


if StrictVersion(__version__) < StrictVersion('20.2'):
    print('your setuptools version does not support PEP 508. Upgrade setuptools and repeat the installation.')
    sys.exit(1)


setup(
    name='spam',
    version='0.1',
    packages=[],
    install_requires=['typing;python_version<"3.5"']
)

这篇关于setup.py:在尝试安装之前,需要最新版本的setuptools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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