简体   繁体   English

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

[英]Python raw_input & Bazel: EOFError: EOF when reading a line

I am attempting to use Bazel as the build system for a python program. 我正在尝试将Bazel用作python程序的构建系统。 I'll use an example of test.py. 我将以test.py为例。 My BUILD file includes: 我的BUILD文件包括:

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

My test.py includes: 我的test.py包括:

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

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

When I run though normal compiler I get: 通过普通的编译器运行时,我得到:

Please enter your name
python
your name is python

However, when I run as bazel run :test I get: 但是,当我以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

Which version of bazel are you using? 您正在使用哪个版本的bazel? In older versions of bazel, the bazel client doesn't connect standard in to the binary when run with bazel run . 在旧版本的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 and --direct_run is a noop. 在0.12及更高版本中,您可以传递--direct_run来连接标准输入。在0.15中,这成为默认值,--direct_run是noop。

You can also run the resulting binary itself (in your example if the build file is at the root of the workspace it would be bazel-bin/test ) 您也可以运行生成的二进制文件本身(在您的示例中,如果构建文件位于工作区的根目录,则它将为bazel-bin/test

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM