make 忽略我的 python bash 别名
我的 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
我有一个 < code>Makefile 其中包含以下几行:
pythonbuild: python setup.py build
令我惊讶的是,我发现正在调用 Python 2.4,而不是 Python 2.7。
我必须显式指定 python2.7
:
pythonbuild: python2.7 setup.py build
make
会忽略 bash 别名吗?我猜 make
使用 PATH
来定位第一个 python
可执行文件(恰好是 Python 2.4)?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自
bash(1)
:虽然您可能能够在
Makefile
中使用SHELL=/bin/bash -O Expand_aliases
之类的内容,但我认为在Makefile
中保持对较新 Python 的显式依赖比将依赖隐藏在用户~/. bash_profile
文件。相反,将
PYTHON=/opt/python2.7/bin/python
放入Makefile
中,然后您可以在规则中使用:。
最好的部分是您可以轻松更改在命令行上使用的 Python 解释器:
如果您将其部署到另一个站点,则只需
Makefile
中的一行需要有待更新。From
bash(1)
:While you might be able to use something like
SHELL=/bin/bash -O expand_aliases
in yourMakefile
, I think keeping an explicit dependency upon the newer Python in yourMakefile
is much better than keeping the dependency hidden in your user~/.bash_profile
file.Instead, put
PYTHON=/opt/python2.7/bin/python
into 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
Makefile
that needs to be updated.别名通常仅由交互式 shell 使用
,请注意,我认为
make
并不总是调用 shell最好的办法是明确你想要使用的路径
aliases are typically just used by interactive shells
Note only that, I think that
make
does not always invoke the shellYour best bet is to be explicit about the paths you want to use
使用 grep 和 awk 的解决方法:
此解决方案的优点是,如果我更改 ~/.bash_profil 或 ~/.bashrc 中的别名,我的 makefile 也会自动采用它。
描述:
我想在我的 makefile 中使用别名 lcw,它的定义与我的 ~/.bashrc 文件中类似。
.bashrc
我还使用其他解决方案中提供的变量定义,但我使用 grep 和 awk 直接从 bashrc 读取其值。
makefile
如您所见,lcw 别名是由 makefile 中的命令
$(LCW)
调用的。注意:
我的解决方案假设 bashrc 中的别名是在“ ”字符内定义的。
Workaround with grep and awk:
The advantage of this solution is that if I change the alias in the ~/.bash_profil or ~/.bashrc, it is automatically adopted by my makefile as well.
Description:
I want to use the alias lcw in my makefile, which is defined like in my ~/.bashrc file.
.bashrc
I use also the definition of a varialble as presented in the other solutions, but I directly read its value from the bashrc by using grep and awk.
makefile
As you see the lcw alias is called by the command
$(LCW)
from the makefile.Note:
My solution assumes that the alias in the bashrc is defined within ' ' characters.