当我使用时:
>>> import http.server
IDLE
中的没有任何错误。
但是当我使用这段代码时:
import http.server
from http.server import BaseHTTPRequestHandler
from http.server import HTTPServer
def run(server_class = HTTPServer, handler_class = BaseHTTPRequestHandler):
server_address = ('', 8000)
httpd=server_class(server_address, handler_class)
httpd.serve_forever()
run()
存在以下错误:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2195, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/toton/Projects/http.py", line 1, in <module>
import http.server
File "/home/toton/Projects/http.py", line 1, in <module>
import http.server
ImportError: No module named 'http.server'; 'http' is not a package
请帮助!
答案 0 :(得分:10)
您已将文件命名为http.py
,因此它会覆盖原始模块http
解决
pyc
文件