Python raw_input和Bazel:EOFError:读一行时出现EOF

时间:2018-07-18 19:20:38

标签: python build stdin bazel

我正在尝试将Bazel用作python程序的构建系统。我将以test.py为例。我的BUILD文件包括:

package(default_visibility = ["//visibility:public"])
py_binary(
    name = "test",
    srcs = [
        "test.py",
    ],
    main = "test.py",
    deps = []
)

我的test.py包括:

name = raw_input("Please enter your name\n")

print "your name is {}".format(name)

当我通过普通编译器运行时,我得到:

Please enter your name
python
your name is python

但是,当我以bazel运行时:test 我得到:

Traceback (most recent call last):
  File "[directory]test.[directory]python_test.py", line 1, in <module>
    name = raw_input("Please enter your name\n")
EOFError: EOF when reading a line
Please enter your name

1 个答案:

答案 0 :(得分:2)

您正在使用哪个版本的bazel?在旧版本的bazel中,使用 <button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">London</button> <script> // Get the element with id="defaultOpen" and click on it document.getElementById("defaultOpen").click(); </script>运行时,bazel客户端无法将标准连接到二进制文件。 In 0.12 and up可以通过bazel run来连接标准输入。在0.15 this became the default中,--direct_run是noop。

您还可以运行生成的二进制文件本身(在您的示例中,如果构建文件位于工作空间的根目录下,则该文件为--direct_run