2011-02-08 183 views
1

由于python传递使用版本3作为默认值,所以需要使用corret python解释器来处理version2代码的执行。我有一个小型的python2项目,我使用make来配置和安装Python包,所以这里是我的问题:我如何确定Makefile内的python版本?如何确定Makefile中的python版本?

这是我想使用的逻辑:如果 (python.version == 3)python2 some_script.py2 其他python3 some_script.py3

提前感谢!

回答

3
python_version_full := $(wordlist 2,4,$(subst ., ,$(shell python --version 2>&1))) 
python_version_major := $(word 1,${python_version_full}) 
python_version_minor := $(word 2,${python_version_full}) 
python_version_patch := $(word 3,${python_version_full}) 

my_cmd.python.2 := python2 some_script.py2 
my_cmd.python.3 := python3 some_script.py3 
my_cmd := ${my_cmd.python.${python_version_major}} 

all : 
    @echo ${python_version_full} 
    @echo ${python_version_major} 
    @echo ${python_version_minor} 
    @echo ${python_version_patch} 
    @echo ${my_cmd} 

.PHONY : all 
0

这可能有助于:SF中的here's a thread关于检查Python版本以控制新的语言功能。

+0

良好的使用它,但我真的需要处理它的Makefile ... – Rizo 2011-02-08 13:03:32

+0

内。在这种情况下,看这里:HTTP:/ /old.nabble.com/Detecting-which-Python-version-is-used-by-SIP-and-PyQt-td30033430.html – 2011-02-08 13:09:18

3

这是一个较短的解决方案。在你的makefile写的顶部:

PYV=$(shell python -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)"); 

然后你就可以用$(PYV)