本文介绍了ubuntu 11.04 lxml导入自定义python的etree问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ubuntu 11.04具有本机python2.7,我将python2.5从源代码构建为/usr/local/python2.5/bin,并尝试为我的自定义python2.5安装安装lxml.我也使用virtualenv.我使用python2.5切换到我的环境.在导入lxml时出现错误.

ubuntu 11.04 has native python2.7 i build python2.5 from source to /usr/local/python2.5/bin, and try to install lxml for my custom python2.5 install. Also i use virtualenv. I switch to my env with python2.5. On import lxml i got an error.

from lxml import etree
ImportError: /home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/lxml-2.2.4-py2.5-linux-i686.egg/lxml/etree.so: undefined symbol: PyUnicodeUCS2_DecodeLatin1

使用python2.7 env,一切正常,但是在python2.5上导入失败.请帮助修复python2.5吗?

With python2.7 env, all is ok but on python2.5 import fails. Please help to fix for python2.5 ?

ldd/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/lxml-2.2.4-py2.5-linux-i686.egg/lxml/etree.so

ldd /home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/lxml-2.2.4-py2.5-linux-i686.egg/lxml/etree.so

结果:

(e-py25)se7en@se7en-R510-P510:~/downloads/lxml-2.2.4$ ldd /home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/lxml-2.2.4-py2.5-linux-i686.egg/lxml/etree.so
    linux-gate.so.1 =>  (0x00968000)
    libxslt.so.1 => /usr/lib/libxslt.so.1 (0x005aa000)
    libexslt.so.0 => /usr/lib/libexslt.so.0 (0x00110000)
    libxml2.so.2 => /usr/lib/libxml2.so.2 (0x00db3000)
    libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0x00a22000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x00564000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x00123000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x0013c000)
    libgcrypt.so.11 => /lib/i386-linux-gnu/libgcrypt.so.11 (0x0029d000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x00d6e000)
    /lib/ld-linux.so.2 (0x004fc000)
    libgpg-error.so.0 => /lib/i386-linux-gnu/libgpg-error.so.0 (0x00879000)
(e-py25)se7en@se7en-R510-P510:~/downloads/lxml-2.2.4$ 

推荐答案

此问题通常是由构建Python而不在./configure命令上使用--enable-unicode=ucs4选项引起的.

This problem is usually caused by building Python without using the --enable-unicode=ucs4 option on the ./configure command.

为确保正确执行操作,请删除现有的Python构建目录,然后通过解压缩Python tarball重新开始构建.

To make sure you do it right, delete the existing Python build directory and start building again by unzipping the Python tarball.

此外,删除现有的Python 2.5安装目录/usr/local/python2.5/并重新构建您构建的其他所有内容,例如lxml.任何使用已编译组件的扩展都将查找Python的构建配置,因此,如果不重建所有内容,则会有不匹配的部分.

Also, delete the existing Python 2.5 install directory /usr/local/python2.5/ and rebuild everything else that you built such as lxml. Any extensions that use compiled components will look up the Python build configuration so if you don't rebuild everything you will have mismatched pieces.

这篇关于ubuntu 11.04 lxml导入自定义python的etree问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 08:37