欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-14 21:15:23
...

代码

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

问题原因

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

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

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

相关标签: python bug