My CentOS 5.5 server has both Python 2.4 and Python 2.7 installed (to /opt/python2.7.2). In my ~/.bash_profile I have two aliases pointing to my Python 2.7 install and my PATH configured as:
alias python=/opt/python2.7.2/bin/python alias python2.7=/opt/python2.7.2/bin/python PATH=$PATH:/opt/python2.7/bin
There’s also a symbolic link I created as well:
ln -sf /opt/python2.7.2/bin/python /usr/bin/python2.7
I have a Makefile which has the following lines:
pythonbuild:
python setup.py build
To my surprise I found that Python 2.4 is being invoked and not Python 2.7.
I have to explicitly specify python2.7:
pythonbuild:
python2.7 setup.py build
Are bash aliases ignored by make? I am guessing make uses PATH to locate the first python executable (which happens to be Python 2.4) instead?
From
bash(1):While you might be able to use something like
SHELL=/bin/bash -O expand_aliasesin yourMakefile, I think keeping an explicit dependency upon the newer Python in yourMakefileis much better than keeping the dependency hidden in your user~/.bash_profilefile.Instead, put
PYTHON=/opt/python2.7/bin/pythoninto yourMakefile, and then you can just use:in your rules.
The best part is you can easily change which Python interpreter you use on the command line:
If you deploy it to another site, it is just one line in the
Makefilethat needs to be updated.