简体   繁体   English

为 python3 安装 libxml2 绑定

[英]Install libxml2 bindings for python3

The Problem问题

I'm trying to build libxml ( libxml2-2.7.8 ) bindings for Python 3.2.我正在尝试为 Python 3.2 构建libxml ( libxml2-2.7.8 ) 绑定。 When I run the following:当我运行以下命令时:

./configure --with-python=/usr/bin/python3.2

The compilation of libxml2-2.7.8 works...but the Python bindings for libxml2-2.7.8 don't! libxml2-2.7.8的编译工作......但libxml2-2.7.8的 Python 绑定不起作用!

Attempted Fixes尝试修复

  1. Ported setup.py and generator.py (using 2to3 , and some basic patches on generator.py )移植setup.pygenerator.py (使用2to3generator.py上的一些基本补丁)
  2. Patched libxml.c and types.c as follows:修补libxml.ctypes.c如下:
    • replace PyInt* by PyLong*用 PyLong* 替换 PyInt*
    • replace PyString* by PyBytes*用 PyBytes* 替换 PyString*

Current Situation现在的情况

Unfortunately, it still wasn't enough.不幸的是,这仍然不够。 I ran python3.2 setup.py build and got the following error:我运行python3.2 setup.py build并得到以下错误:

types.c:594:17: error: ‘PyInstanceObject’ undeclared (first use in this function)

I can't find the Python3 equivalent of PyInstanceObject !我找不到 PyInstanceObject 的PyInstanceObject等价物!

Has anyone managed to compile libxml2 bindings for Python 3?有没有人设法为 Python 3 编译libxml2绑定?

Did I miss something???我错过了什么??? Can anybody help?有人可以帮忙吗? :( :(

The PyInstanceObject is a part of the support for old style types, which is gone in Python 3 , and has been deprecated since Python 2.2. PyInstanceObject 是对旧样式类型的支持的一部分,它在 Python 3 中消失了,并且自 Python 2.2 起已被弃用。 The trick here is to first update the bindings to use new-style classes, and then port to Python 3.这里的技巧是首先更新绑定以使用新样式的类,然后移植到 Python 3。

(Or use lxml, which wraps the libxml2 in a Pythonic XML classes). (或使用 lxml,它将 libxml2 包装在 Pythonic XML 类中)。

I'm not 100% sure what the replacement is, I've never done old-style classes in C, but I think it's simply a PyObject.我不是 100% 确定替换是什么,我从未在 C 中做过旧式类,但我认为它只是一个 PyObject。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM