使用 py2exe 打包 python 脚本后查找错误
我编写了一个绑定到套接字的 python 脚本,如下所示:
from socket import *
addr = (unicode(), 11111)
mySocket = socket(AF_INET, SOCK_STREAM)
mySocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
mySocket.bind(addr)
我使用 setup.py 将此脚本与 py2exe 一起打包,并带有以下选项:
setup(
console=["myProgram.py"],
options = {"py2exe": {"compressed": 1,
"optimize": 2,
"bundle_files": 1,
"excludes": ["w9xpopen.exe"],
"packages": ["encodings","codecs"],
}},
zipfile = None)
在 Python 2.5 下,这可以正常工作。但是,当我在 python 2.6 下打包源代码时,出现以下错误:
Traceback (most recent call last):
File "Mod_CommsServ.pyo", line 201, in __init
File "<string>", line 1, in bind
LookupError: unknown encoding: idna
如您所见,我已经包含了 py2exe 的编码,但可执行文件仍然无法解析“idna”。有人可以帮助我吗?
I have written a python script which binds to a socket like this:
from socket import *
addr = (unicode(), 11111)
mySocket = socket(AF_INET, SOCK_STREAM)
mySocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
mySocket.bind(addr)
I package this script with py2exe using setup.py with the following options:
setup(
console=["myProgram.py"],
options = {"py2exe": {"compressed": 1,
"optimize": 2,
"bundle_files": 1,
"excludes": ["w9xpopen.exe"],
"packages": ["encodings","codecs"],
}},
zipfile = None)
Under Python 2.5 this works fine. However, when I package the source under python 2.6, I get the following error:
Traceback (most recent call last):
File "Mod_CommsServ.pyo", line 201, in __init
File "<string>", line 1, in bind
LookupError: unknown encoding: idna
As you can see, I already included encodings for py2exe, but the executable still is not able to resolve 'idna'. Can anybody help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为您传递一个 unicode 字符串作为主机名,所以 python2.6 假定需要发生“IDNA”(应用程序中的国际化域名)。
只需使用即可。
除非您有充分的理由需要 IDNA 支持,否则
Because you pass a unicode string as hostname, python2.6 assumes "IDNA" (Internationalized Domain Names in Applications) needs to take place.
Just use
in stead, unless you have very good reasons to require IDNA support.