【问题标题】:Python subprocess.Popen Not finding ExecutablePython subprocess.Popen 找不到可执行文件
【发布时间】:2013-11-13 10:21:47
【问题描述】:

我在使用 Python 在我的 Linux 机器上查找可用的可执行文件时遇到问题。我的默认 PATH 包含此可执行文件(svnlook),但是当我运行 python 脚本时,以下函数无法找到可执行文件。有关如何解决此问题的任何想法?

def command_output(cmd):
    child  = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
    output = child.communicate()[0]
    return output, child.returncode


def get_author():
    cmd = "svnlook author %s %s %s" % (svn_opt, svn_txn, svn_repo)
    author, return_code = command_output(cmd)

    return author.strip()

错误:

 Traceback (most recent call last):
  File "/home/user/app/csvn/data/repositories/repo/hooks/pre-commit", line 82, in <module>
    author = get_author()
  File "/home/user/app/csvn/data/repositories/repo/hooks/pre-commit", line 53, in get_author
    author, return_code = command_output(cmd)
  File "/home/user/app/csvn/data/repositories/repo/hooks/pre-commit", line 36, in command_output
    child  = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
  File "/home/user/app/activepython-2.7.2.5_x86_64/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/home/user/app/activepython-2.7.2.5_x86_64/lib/python2.7/subprocess.py", line 1228, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
Error: [Errno 2] No such file or directory

【问题讨论】:

  • 为什么这被否决了?
  • 请发布完整的回溯。
  • 你没有找到一个可执行文件而不是一个进程。
  • @hcwhsa 添加了回溯,有什么想法吗?
  • 尝试从 Python 打印您的 sys.path 并查看路径是否正确传递给 Python。另外尝试使用完整路径运行svnlook,看看它是否解决了问题。我还要确保 svnlook 不是别名 - 这是 bash 内部的,不能传递给正在运行的程序。

标签: python


【解决方案1】:

您可能希望提供可执行文件的完整路径,例如/usr/bin/svnlook/usr/local/bin/svnlook 而不仅仅是 svnlook

详情请见this answer to a related question

【讨论】:

    【解决方案2】:

    尝试从控制台运行它。确保权限/可执行性正确。试试 os.system()。

    【讨论】:

      猜你喜欢
      • 2021-11-30
      • 2014-06-27
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多