Getting 'OSError: [Errno 2] No such file or directory' on popen when trying to run mypy

Getting 'OSError: [Errno 2] No such file or directory' on popen when trying to run mypy

你好堆栈溢出用户,

我在尝试让 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指定cache-dir和traceback,python_files是要测试的问题文件。我相当有信心这些论点都不是问题,因为我已经尝试过这些论点但没有取得任何进展。

此文件位于 git 存储库中,我已将其克隆并放入构建盒中。在本地这不是问题——我得到有效的 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 错误开始被抑制,加上被认为是不好的 style/security 问题。

我的 guess/thought 是,如果没有 shell,mypy 可能不在 popen 使用的路径中,但我真的不确定。

好吧,刚刚弄清楚我的问题,而且很明显...糟糕!

已修复:python3 -m pip install -U mypy==0.530

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