Nem*_*emo 3 python linux bash popen pycharm
我在.bashrc中添加了mytool的路径,我可以mytool --help从bash shell中的任何路径运行.但是,当我运行以下代码片段时,我得到:
文件"/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()
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
编辑:当我从终端(bash)运行python文件时,它工作正常.但是当我从PyCharm(调试器)或其他shell运行时,它会给出上述错误.
当我从其他shell运行脚本时,如何更改我的脚本以便它在bash中运行'mytool'?我需要在.bashrc中添加的环境
将此打印添加到您的文件中:
import os
print os.environ['PATH']
Run Code Online (Sandbox Code Playgroud)
从IDE和终端运行脚本后比较输出.
您应该注意到IDE PATH不包含该mytool目录.
| 归档时间: |
|
| 查看次数: |
14328 次 |
| 最近记录: |