Python http.server命令给出;语法错误“;

Python http.server命令给出;语法错误“;,python,Python,我试图从Python shell(Python3.6.2)启动http.server。在shell中,我发出以下命令: import http.server import socketserver python -m http.server 8000 --bind 127.0.0.1 最后一行直接来自最新版本,但shell显示“语法错误” 然后我试着: python3 -m http.server 8000 --bind 127.0.0.1 但是shell仍然显示“语法错误” 然后我尝试了最

我试图从Python shell(Python3.6.2)启动http.server。在shell中,我发出以下命令:

import http.server
import socketserver
python -m http.server 8000 --bind 127.0.0.1
最后一行直接来自最新版本,但shell显示“语法错误”

然后我试着:

python3 -m http.server 8000 --bind 127.0.0.1
但是shell仍然显示“语法错误”

然后我尝试了最简单的命令:

python -m http.server also says "Syntax Error":  
但是shell仍然显示“语法错误”

我做错了什么


谢谢你的帮助

因为你无法理解我们在评论中的意思;您需要运行该命令

python -m http.server 8000 --bind 127.0.0.1
python -m http.server 8000 --bind 127.0.0.1
在bash(或类似的)shell中,不是来自python空闲解释器的。它们的意思不一样。您必须在shell中键入命令
python
,才能获得python空闲解释器

如果您在python解释器中并且想要退出,请按Ctrl+D返回到bash(或类似的)shell。然后,执行命令

python -m http.server 8000 --bind 127.0.0.1
python -m http.server 8000 --bind 127.0.0.1
它应该会起作用


您是对的,httpserver的python文档可以更加清晰,但是您应该知道,当您看到对
python
的调用时,几乎可以肯定它是从一个shell发出的。

python-mhttp.server 8000--bind 127.0.0.1
在python中不是有效的命令。您从何处获得这些代码?正如我所说,这些代码直接来自最新的Python文档。您希望从shell而不是Python中运行该命令interpreter@RTC222
“shell”!=“python交互式命令行”
交互式命令行不是shell
python
是一个shell可执行文件,但您试图将其用作python命令。谢谢您的回答。我通常在IDE中开发,因此我不太熟悉仅使用Python命令行。关于这一点的文件不清楚,可用的研究也不清楚。非常感谢您的澄清。堆栈溢出不允许我在您发布后的几分钟内接受您的答案。那一段时间过后我会的。多谢。