【发布时间】:2012-04-13 16:14:38
【问题描述】:
我有一些自定义命令。
# works
subprocess.Popen(['python'], stdout=subprocess.PIPE)
但如果我有自己的系统命令,例如 deactivate,我会收到该错误
Traceback (most recent call last):
File "runner2.py", line 21, in <module>
main()
File "runner2.py", line 18, in main
subprocess.Popen(['deactivate',], stdout=subprocess.PIPE)
File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
更不用说我需要在我的沙盒 virtualenv 下执行这个了。
【问题讨论】:
-
当您的脚本运行时,
python可能不在PATH环境变量中。尝试设置python的完整路径,即/usr/bin/python。 -
你能解释一下你想要完成什么吗?我怀疑您使用
subprocess启动的子 shell 没有“获取”virtualenv 激活脚本,并且它不是从父 Python 进程继承的(假设您从那里运行它)。
标签: python subprocess popen