python-2.7libxml2centos7libxslt

Can not import libxml2 and libxslt in Python 2.7 and CentOS 7


Can not import libxml2 and libxslt in Python 2.7 and CentOS 7.

But system says that these packages are installed:

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

But can not import in 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
>>> 

Solution

  • libxml2 install step

    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 install step

    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
    

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