当我从空闲服务器导入'http.server'时,它可以工作,但是当我运行一个包含'import http.server'的python文件时,出现了一个错误
当我使用:当我从空闲服务器导入'http.server'时,它可以工作,但是当我运行一个包含'import http.server'的python文件时,出现了一个错误,python,http,python-3.x,module,Python,Http,Python 3.x,Module,当我使用: >>> import http.server 在空闲状态下没有任何错误。 但当我使用这段代码时: import http.server from http.server import BaseHTTPRequestHandler from http.server import HTTPServer def run(server_class = HTTPServer, handler_class = BaseHTTPRequestHandler): ser
>>> import http.server
在空闲状态下
没有任何错误。
但当我使用这段代码时:
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
回溯(最近一次呼叫最后一次):
文件“”,第2195行,在“查找”和“加载”中解锁
AttributeError:“模块”对象没有属性“\u_路径”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“/home/toton/Projects/http.py”,第1行,在
导入http.server
文件“/home/toton/Projects/http.py”,第1行,在
导入http.server
ImportError:没有名为“http.server”的模块;'“http”不是一个包
请帮忙 您已将文件命名为
http.py
,因此它将覆盖原始模块http
解决
- 将文件名更改为其他名称
- 删除
文件pyc
- 再次运行程序