Python SyntaxError:编译单个语句时发现多个语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21226808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:21:11  来源:igfitidea点击:

SyntaxError: multiple statements found while compiling a single statement

pythonsyntax-errorpython-3.3

提问by user3213857

I'm in Python 3.3 and I'm only entering these 3 lines:

我在 Python 3.3 中,我只输入这 3 行:

import sklearn as sk
import numpy as np
import matplotlib.pyplot as plt

I'm getting this error:

我收到此错误:

SyntaxError: multiple statements found while compiling a single statement

What could I be doing wrong?

我可能做错了什么?

Edit: If anyone comes across this question, the solution I found was to download Idlex and use its IDLE version, which allows multiple lines.

编辑:如果有人遇到这个问题,我找到的解决方案是下载 Idlex 并使用它的 IDLE 版本,它允许多行。

Screenshot: http://imgur.com/AJSrhhD

截图:http: //imgur.com/AJSrhhD

回答by aIKid

In the shell, you can't execute more than one statement at a time:

在 shell 中,您一次不能执行多个语句:

>>> x = 5
y = 6
SyntaxError: multiple statements found while compiling a single statement

You need to execute them one by one:

您需要一一执行它们:

>>> x = 5
>>> y = 6
>>>

When you see multiple statements are being declared, that means you're seeing a script, which will be executed later. But in the interactive interpreter, you can't do more than one statement at a time.

当您看到声明了多个语句时,这意味着您看到的是一个脚本,该脚本将在稍后执行。但是在交互式解释器中,您一次不能执行多个语句。