我正在尝试在我的机器上设置 http 服务器,但出现错误:
ModuleNotFoundError: No module named 'http.server'; 'http' is not a package
Run Code Online (Sandbox Code Playgroud)
我的项目目录中有 2 个文件:http.py和index.html.
这是http.py:
import http.server
import socketserver
PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)
我已经尝试将模块更改为BaseHTTPServer,但出现此错误:
ModuleNotFoundError: No module named 'BaseHTTPServer'
Run Code Online (Sandbox Code Playgroud)
我还注意到我的终端上发生了一件奇怪的事情。如果我尝试做
python3 -m pip uninstall <module>
Run Code Online (Sandbox Code Playgroud)
我收到一个错误,例如
ModuleNotFoundError: No module named 'http.server'; 'http' is not a package
Run Code Online (Sandbox Code Playgroud)
这让我失望,因为我什至没有运行该文件。我提到这一点以防万一表明某些本地配置可能是所有人的问题。