我的CentOS 5.5服务器安装了Python 2.4和Python 2.7 /opt/python2.7.2
.在我的~/.bash_profile
我有两个别名指向我的Python 2.7安装和我PATH
配置为:
alias python=/opt/python2.7.2/bin/python alias python2.7=/opt/python2.7.2/bin/python PATH=$PATH:/opt/python2.7/bin
我还创建了一个符号链接:
ln -sf /opt/python2.7.2/bin/python /usr/bin/python2.7
我有一个Makefile
有以下几行:
pythonbuild: python setup.py build
令我惊讶的是,我发现Python 2.4正在被调用而不是Python 2.7.
我必须明确指出python2.7
:
pythonbuild: python2.7 setup.py build
是否忽略了bash别名make
?我猜测make
用于PATH
定位第一个python
可执行文件(恰好是Python 2.4)?
来自bash(1)
:
Aliases are not expanded when the shell is not interactive,
unless the expand_aliases shell option is set using shopt
(see the description of shopt under SHELL BUILTIN COMMANDS
below).
Run Code Online (Sandbox Code Playgroud)
虽然你也许能够使用的东西,像SHELL=/bin/bash -O expand_aliases
你Makefile
,我想保持在较新的Python的显式依赖于你的Makefile
是多少不是让藏在你的依赖更好的用户 ~/.bash_profile
文件.
相反,放入PYTHON=/opt/python2.7/bin/python
你的Makefile
,然后你可以使用:
pythonbuild:
$(PYTHON) setup.py build
Run Code Online (Sandbox Code Playgroud)
在你的规则中.
最好的部分是您可以轻松更改在命令行中使用的Python解释器:
make PYTHON=/tmp/python-beta/bin/python pythonbuild
Run Code Online (Sandbox Code Playgroud)
如果将其部署到另一个网站,它只是一个在该行Makefile
需要进行更新.