我正在尝试编写一个小脚本来远程管理Windows计算机(目前只能关机)。我使用的方法涉及webapp2服务器。我想将我的第一次尝试编译成 .exe 文件。问题在于,成功编译后运行它时会返回错误:
Traceback (most recent call last):
File "web2.py", line 2, in <module>
File "webapp2.pyc", line 25, in <module>
File "webob\__init__.pyc", line 1, in <module>
File "webob\datetime_utils.pyc", line 10, in <module>
ImportError: No module named email.utils
我也尝试过使用cx_Freeze,结果类似。我按照import error while bundling using py2exe中给出的建议进行了操作,但无济于事。
如果有用的话,这是我的代码:
import cgi
import webapp2
import os
import socket
def ip():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('google.com', 0))
return s.getsockname()[0]
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write("""
<html>
<body>
<form action="/shutdown" method="link">
<div><input type="submit" value="Shutdown"></div>
</form>
</body>
</html>""")
class shutdown(webapp2.RequestHandler):
def get(self):
self.response.out.write('<html><body>Shutting down...<pre>')
self.response.out.write('</pre></body></html>')
os.system("shutdown -p -f")
app = webapp2.WSGIApplication([('/', MainPage),
('/shutdown', shutdown)],
debug=True)
def main():
from paste import httpserver
httpserver.serve(app, host=ip(), port='80')
if __name__ == '__main__':
main()
感谢您的提前帮助。
编辑:
我使用 modulefinder 发现有很多模块没有被导入。然而,我不知道这是在正常运行时发生还是仅在导入时发生或类似情况。 http://pastebin.com/s0U9WHJ6
import email.utils
并使用 py2exe 重新生成 .exe 文件,这是否有帮助? - Luke Woodwardrfc822
模块。然而,我不知道这有多大关联。 - Luke Woodward