Python raw_input & Bazel: EOFError: EOF when reading a line
Python raw_input & Bazel: EOFError: EOF when reading a line
我正在尝试使用 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
您使用的是哪个版本的 bazel?在旧版本的 bazel 中,当 运行 和 bazel run
时,bazel 客户端不会将标准连接到二进制文件。 In 0.12 and up you can pass --direct_run
to connect standard in. In 0.15 this became the default 和 --direct_run
是空话。
您还可以 运行 生成的二进制文件本身(在您的示例中,如果构建文件位于工作区的根目录下,它将是 bazel-bin/test
)
我正在尝试使用 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
您使用的是哪个版本的 bazel?在旧版本的 bazel 中,当 运行 和 bazel run
时,bazel 客户端不会将标准连接到二进制文件。 In 0.12 and up you can pass --direct_run
to connect standard in. In 0.15 this became the default 和 --direct_run
是空话。
您还可以 运行 生成的二进制文件本身(在您的示例中,如果构建文件位于工作区的根目录下,它将是 bazel-bin/test
)