我正在使用Ubuntu 12.4,并且我安装了matlab。通常,为了从终端调用matlab,我必须键入'〜/ MATLAB/bin/matlab'。显然这有点恼人,所以我给别名加了这个命令:别名Linux命令不能从python识别(commands.getoutput)
alias matlab='sh ~/MATLAB/bin/matlab'
to .bashrc。现在一切都很好,在终端(bash)中输入'matlab'可以在任何目录下工作。
当我试图从python脚本调用Matlab时出现问题。有这样的说法:
>>> commands.getoutput('matlab')
'sh: 1: matlab: not found'
因为它似乎别名没有被识别。 只是为了确保:
>>> commands.getoutput('~/MATLAB/bin/matlab')
的作品就像一个魅力和
>>> commands.getoutput('echo $SHELL')
'/bin/bash'
确实验证了蟒蛇正试图执行在bash的CMD ...
任何想法,这里发生了什么?为什么不认可别名?如何/可以修复?
谢谢!
'命令'已弃用。考虑使用子流程(http://docs.python.org/library/subprocess.html#module-subprocess)。 – mgilson 2012-08-01 14:25:21
快速问题 - 如果将别名放在'.bash_profile'中会发生什么? – mgilson 2012-08-01 14:28:17
有关背景信息,请参阅http://stackoverflow.com/questions/5971312/how-to-set-environmental-variables-in-python – Anton 2012-08-01 14:36:11