代码

import http.server
import socketserver

PORT = 8000

Handler = http.server.SimpleHTTPRequestHandler

with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()

报错

python报错解决:ModuleNotFoundError: No module named ‘http.server‘; ‘http‘ is not a package_bug

问题原因

py文件名称与包的名称发生冲突!

这里的错误便是py文件的命名为http.py导致import发生冲突!

python报错解决:ModuleNotFoundError: No module named ‘http.server‘; ‘http‘ is not a package_bug_02