无法在Python 2.7和CentOS 7中导入libxml2和libxslt

时间:2015-10-14 05:42:33

标签: python-2.7 libxml2 centos7 libxslt

无法在libxml2libxslt中导入Python 2.7CentOS 7

但系统说安装了这些软件包:

Package libxml2-2.9.1-5.el7_1.2.x86_64 already installed and latest version
Package libxml2-devel-2.9.1-5.el7_1.2.x86_64 already installed and latest version
Package libxslt-1.1.28-5.el7.x86_64 already installed and latest version
Package libxslt-devel-1.1.28-5.el7.x86_64 already installed and latest version

但无法在Python2.7中导入

Python 2.7.5 (default, Jun 24 2015, 00:41:19) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import libxml2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named libxml2
>>> import libxslt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named libxslt
>>> 

1 个答案:

答案 0 :(得分:2)

libxml2安装步骤

yum groupinstall "Development Tools"

yum  install python-devel.x86_64

rpmbuild -ba /usr/src/redhat/SPECS/libxml2.spec (this might not be required.)

##go to  RPMS/x86_64/

rpm -Uvh libxml2-python-2.7.8-1.x86_64.rpm --nodeps

=============================================== ====================

libxslt安装步骤

wget  http://xmlsoft.org/sources/libxslt-1.1.28.tar.gz

cd libxslt-1.1.28

./configure --with-python=/usr/bin/python2.7

make

make install

========================================