Windows 上的 Python lxml 中缺少编码
我正在尝试使用 lxml 2.3 在 Windows 上的 Python 2.7 中运行这一小段代码。
from lxml import etree
p = etree.XMLParser(encoding='cp1252')
根据
LookupError: unknown encoding: 'cp1252'
我的理解,lxml 使用 libxml2,而 libxml2 又依赖于 libiconv 来处理像这样的字符编码。但是,只有基本编码(例如 ascii 或 utf-8)可以工作。
有谁知道为什么我无法使用其他编码?尽管 libiconv 应该包含在 lxml 二进制包中,但它是否未以某种方式加载?
谢谢!
已解决:
我通过卸载适用于 Windows 的 64 位版本的 Python 并安装 32 位版本以及 lxml 2.3 的 32 位二进制版本来解决此问题。目前尚不清楚问题是什么,但我怀疑 lxml 的 64 位二进制版本不包含 libiconv 或者无法以某种方式链接到它。
感谢所有阅读本文并试图提供帮助的人!
I'm trying to run this little bit of code in Python 2.7 on Windows, using lxml 2.3.
from lxml import etree
p = etree.XMLParser(encoding='cp1252')
which returns
LookupError: unknown encoding: 'cp1252'
From what I understand, lxml uses libxml2, which in turn depends on libiconv for handling character encoding such as this one. However, only basic encodings such as ascii or utf-8 are working.
Does anyone have an idea why I'm unable to use other encodings? Is libiconv not being loaded somehow, even though it should be included in the lxml binary package?
Thanks!
Solved:
I solved this by uninstalling my 64-bit version of Python for Windows and installing the 32-bit version, along with the 32-bit binary build of lxml 2.3. It's not clear what the problem was, but I suspect that the 64-bit binary build of lxml didn't include libiconv or was unable to link to it somehow.
Thanks to everyone who read this and tried to help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论