在 setup.py 中强制执行 python 版本 [英] Enforcing python version in setup.py

查看:31
本文介绍了在 setup.py 中强制执行 python 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我们正在通过在 install_requires 属性下的 setup.py 中提及它们的版本和依赖项来在系统上设置\安装一些软件包.我们的系统需要 Python 2.7.有时,用户在他们的系统上有多个版本的 Python,比如 2.6.x 和 2.7,它说有些包已经可用,但实际上在 2.6 站点包列表下可用的系统上.还有一些用户只有 2.6,如何从 setup.py 强制执行,或者有没有其他方法可以说只有 Python 2.7 和我们想要的所有包 setup.py更新仅适用于 2.7.我们要求机器上的最低版本为 2.7 才能运行我们的代码.

Currently, we are setting\installing up some packages on system by mentioning their version and dependencies in setup.py under install_requires attribute. Our system requires Python 2.7. Sometimes, users are having multiple versions of Python on their systems, say 2.6.x and 2.7, some packages it says are available already but actually on the system available under 2.6 site packages list. Also some users have 2.6 only, how to enforce from setup.py or is there any other way to say to have only Python 2.7 and all packages which we want setup.py to update are for only 2.7. We require minimum 2.7 on the machine to run our code.

谢谢!桑托斯

推荐答案

由于 setup.py 文件是通过 pip(和 pip> 本身由 python 解释器运行)无法在 setup.py 文件中指定要使用的 Python 版本.

As the setup.py file is installed via pip (and pip itself is run by the python interpreter) it is not possible to specify which Python version to use in the setup.py file.

而是查看这个答案setup.py:限制 python 解释器的允许版本,它有一个基本的解决方法来停止安装.

Instead have a look at this answer to setup.py: restrict the allowable version of the python interpreter which has a basic workaround to stop the install.

在您的情况下,代码将是:

In your case the code would be:

import sys
if sys.version_info < (2,7):
    sys.exit('Sorry, Python < 2.7 is not supported')

这篇关于在 setup.py 中强制执行 python 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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