问题
Hi I try to set up my first simple Python http server. This is what I tried. Please help.
>>>import os
>>>os.chdir('/users/ds/my documents/pythonservers/frenchacademy')
>>>os.getcwd()
'C:\\users\\ds\\my documents\\pythonservers\\frenchacademy'
>>> python -m SimpleHTTPServer
SyntaxError: invalid syntax
>>> python -m SimpleHTTPServer 8000
SyntaxError: invalid syntax
>>> -m SimpleHTTPServer
SyntaxError: invalid syntax
>>> python -m http.server
SyntaxError: invalid syntax
>>> -m http.server
SyntaxError: invalid syntax
>>> --version
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
--version
NameError: name 'version' is not defined
>>> python --version
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
python --version
NameError: name 'python' is not defined
>>> $ python -m http.server
SyntaxError: invalid syntax
>>> python3 -m http.server
SyntaxError: invalid syntax
>>> -m http.server
SyntaxError: invalid syntax
>>> python3 -m http.server --help
SyntaxError: invalid syntax
回答1:
Fund the solution. As usually a stupid error. I had to put the command in the windows command line and not in python itself.
来源:https://stackoverflow.com/questions/27568283/python-3-http-server-syntax-error