【问题标题】:Getting 'OSError: [Errno 2] No such file or directory' on popen when trying to run mypy尝试运行 mypy 时弹出“OSError:[Errno 2] No such file or directory”
【发布时间】:2017-11-01 23:45:38
【问题描述】:

你好堆栈溢出用户,

我很难让 mypy 与 Popen 一起正常工作。本质上,我正在编写一个使用 mypy 但似乎无法在我的构建机器上获得有效输出的测试套件。

有问题的行如下:

p = subprocess.Popen(['mypy'] + extra_args + python_files, env=my_env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIP)

extra_args 指定缓存目录和回溯,python_files 是要测试的有问题的文件。我相当有信心这些论点都不是问题,因为我已经尝试过这些论点并且没有取得任何进展。

这个文件在一个 git repo 中,我已经克隆了它并把它放在一个构建框上。在本地这不是问题——我得到有效的 mypy 输出指示错误。但是,在我的构建机器上,我收到了 OSError: [Errno 2] No such file or directory 错误。完整的错误信息如下:

Traceback (most recent call last):
  File "mypath/run_mypy.py", line 83, in <module>
    main()
  File "mypath/run_mypy.py", line 70, in main
    p = subprocess.Popen(['mypy'] + extra_args + python_files, env=my_env, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
  File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
myotherpath/build-stack.mk:162: recipe for target 'mypy' failed

我尝试添加 shell=True 但这导致所有 mypy 错误开始被抑制,并且被认为是错误的样式/安全问题。

我的猜测/想法是 mypy 可能不在 popen 在没有外壳的情况下使用的路径中,但我真的不确定。

【问题讨论】:

    标签: python popen mypy


    【解决方案1】:

    好的,刚刚发现我的问题,而且很明显……哎呀!

    这修复了它:python3 -m pip install -U mypy==0.530

    原来我没有在盒子上安装mypy。该错误消息使我误入歧途,因为我认为它指的是我传递的参数之一,而不是实际的命令。希望这对将来的某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-06-07
      • 2017-07-05
      • 2018-11-20
      • 2018-07-24
      • 1970-01-01
      • 2019-03-25
      • 2018-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多