Installing lxml module in python

后端 未结 7 2101
温柔的废话
温柔的废话 2020-12-02 09:52

while running a python script, I got this error

  from lxml import etree
ImportError: No module named lxml

now I tried to install lxml

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 10:20

    For RHEL/CentOS, run "python --version" command to find out Python version. E.g. below:

    $ python --version 
      Python 2.7.12
    

    Now run "sudo yum search lxml" to find out python*-lxml package.

    $ sudo yum search lxml
    Failed to set locale, defaulting to C
    Loaded plugins: priorities, update-motd, upgrade-helper
    1014 packages excluded due to repository priority protections
    ============================================================================================================= N/S matched: lxml =============================================================================================================
    python26-lxml-docs.noarch : Documentation for python-lxml
    python27-lxml-docs.noarch : Documentation for python-lxml
    python26-lxml.x86_64 : ElementTree-like Python bindings for libxml2 and libxslt
    python27-lxml.x86_64 : ElementTree-like Python bindings for libxml2 and libxslt
    

    Now you can choose package as per your Python version and run command like below:

    $ sudo yum install python27-lxml.x86_64
    

提交回复
热议问题