【发布时间】:2013-10-28 23:30:49
【问题描述】:
我在.bash_profile 中添加了一个新别名python3.3,以便轻松启动python3.3 版本的pyzo。
我可以在终端中毫无问题地使用此别名,但是当我使用 subprocess.check_call(args = ["python3.3", onePyFile]) 之类的名称时,出现以下错误。
Traceback (most recent call last):
...
File "/Library/Frameworks/pyzo2013b/lib/python3.3/subprocess.py", line 540, in check_call
retcode = call(*popenargs, **kwargs)
File "/Library/Frameworks/pyzo2013b/lib/python3.3/subprocess.py", line 521, in call
with Popen(*popenargs, **kwargs) as p:
File "/Library/Frameworks/pyzo2013b/lib/python3.3/subprocess.py", line 818, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/pyzo2013b/lib/python3.3/subprocess.py", line 1416, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'python3.3'
我猜我的别名不是到处都能看到的。那么我该如何解决我的问题呢?建立自己的别名的好方法是什么?
如果我尝试subprocess.check_call(args = ["python3.3", onePyFile], shell = True),则会出现以下错误。
onePyFile.py: python3.3: command not found
Traceback (most recent call last):
File "mainFile.py", line 72, in <module>
shell = True
File "/Library/Frameworks/pyzo2013b/lib/python3.3/subprocess.py", line 545, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['python3.3', 'onePyFile.py']' returned non-zero exit status 127
如果我只使用subprocess.check_call(args = ["python3.3", onePyFile]),其中onePyFile 的第一行是#! /usr/bin/env python3.3,则会出现以下错误。
env: python3.3: No such file or directory
Traceback (most recent call last):
...
我认为我的问题更多是关于符号链接而不是 Python 调用。但我不知道出了什么问题。事实上,这是我第一次使用别名创建个人符号链接。
【问题讨论】:
-
如果您是这样想的,请摆脱符号链接并使用 python 3.3 的完整路径。您可能还需要 onePyFile 的完整路径。
-
我知道我可以做到,但我也想知道如何解决别名问题。
标签: python unix subprocess