我在.bashrc中添加了mytool的path,我可以从bash shell的任何path运行mytool --help
。 但是当我运行下面的代码片段时,我得到:
文件“/usr/lib/python2.7/subprocess.py”,行1249,在_execute_child中引发child_exception OSError:[Errno 2]没有这样的文件或目录
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()
我该如何解决这个问题?
编辑:当我从terminal(bash)运行python文件,它工作正常。 但是当我从PyCharm(debugging器)或其他shell运行它是给出上述错误。
如何改变我的脚本,使其在bash中运行脚本时使用“mytool”? 我需要在.bashrc中添加环境
将此打印添加到您的文件中:
import os print os.environ['PATH']
从IDE和终端运行脚本后比较输出。
您应该注意到IDE的PATH
不包含mytool
的目录。
去:
Run/Debug Configurations
– > Environment variables
添加休闲:
PATH
=输出到你的shell echo $PATH