Python ModuleNotFoundError: 没有名为“BaseHTTPServer”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45229030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ModuleNotFoundError: No module named 'BaseHTTPServer'
提问by Cody Vollrath
So I am trying to follow a tutorial online on how to work with web.py, and I got it installed but unfortunately, using this piece of code yields a nasty error. My Code...
因此,我正在尝试在线学习如何使用 web.py 的教程,并且我安装了它,但不幸的是,使用这段代码会产生一个令人讨厌的错误。我的代码...
import web
urls = (
'/(.*)', 'index'
)
app = web.application(urls, globals())
class index:
def GET(self, name):
return "Hello", name, '. How are you today?'
if __name__== "__main__":
app.run()
MY ERROR:
我的错误:
C:\Users\User\AppData\Local\Programs\Python\Python36-32\python.exe C:/Users/User/PycharmProjects/Webprojects/main.py
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/Webprojects/main.py", line 15, in <module>
app.run()
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\application.py", line 312, in run
return wsgi.runwsgi(self.wsgifunc(*middleware))
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\wsgi.py", line 59, in runwsgi
return httpserver.runsimple(func, server_addr)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\httpserver.py", line 154, in runsimple
func = LogMiddleware(func)
File "C:\Users\User\AppData\Local\Programs\Python\Python36-32\lib\site-packages\web\httpserver.py", line 296, in __init__
from BaseHTTPServer import BaseHTTPRequestHandler
ModuleNotFoundError: No module named 'BaseHTTPServer'
Process finished with exit code 1
采纳答案by Nathan V
That import line won't work in Python 3 which moved BaseHTTPServer
to http.server.HTTPServer
那进口线不会在Python 3中移动合作BaseHTTPServer
,以http.server.HTTPServer
In your specific case you should update web.py to the current version that works with Python 3.
在您的特定情况下,您应该将 web.py 更新为适用于 Python 3 的当前版本。