我已经在.bashrc中将路径添加到mytool,并且可以从bash shell中的任何路径运行mytool --help
。但是,当我运行以下代码片段时,会得到:
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory
import subprocess
command_array = ['mytool', '--help']
p = subprocess.Popen(command_array,
stderr=subprocess.STDOUT, stdout=subprocess.PIPE,
)
for line in iter(p.stdout.readline, b''):
print(line)
p.stdout.close()
我该怎么解决?
编辑:当我从终端(bash)运行python文件时,它工作得很好。但是当我从PyCharm(调试器)或其他shell运行时,它给出了上述错误。
当我从其他shell运行脚本时,如何更改脚本使其在bash中运行“mytool”?我需要在.bashrc中添加环境
将此打印添加到您的文件:
从IDE和终端运行脚本后比较输出。
您应该注意到IDE的
PATH
不包括mytool
的目录。转到:
Run/Debug Configurations
->;Environment variables
添加休闲:
PATH
=输出到shellecho $PATH
相关问题 更多 >
编程相关推荐