How can I find the installed python-lxml version in a Linux system?
>>> import lxml >>> lxml.__version__ Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute '__version__' >>> from pprint import pprint >>> pprint(dir(lxml)) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'get_include', 'os'] >>>
Can't seem to find it
In case you want to use the current in-development version of lxml, you can get it from the github repository at https://github.com/lxml/lxml . Note that this requires Cython to build the sources, see the build instructions on the project home page.
Note: If you wish to install any particular version of lxml, you can simply state it when you run the command in the command prompt or terminal like this, lxml==3. x.y . By now, you should have a copy of the lxml library installed on your local machine.
lxml has been downloaded from the Python Package Index millions of times and is also available directly in many package distributions, e.g. for Linux or macOS.
Python lxml is the most feature-rich and easy-to-use library for processing XML and HTML data. Python scripts are written to perform many tasks like Web scraping and parsing XML. In this lesson, we will study about python lxml library and how we can use it to parse XML data and perform web scraping as well.
You can get the version by looking at etree
:
>>> from lxml import etree >>> etree.LXML_VERSION (3, 0, -198, 0)
Other versions of interest can be: etree.LIBXML_VERSION
, etree.LIBXML_COMPILED_VERSION
, etree.LIBXSLT_VERSION
and etree.LIBXSLT_COMPILED_VERSION
.
I assume you want to determine lxml
's version programatically from Python. Since lxml
does not provide this information via way of a typilca __version__
attribute on the top-level package you will have to resort to using setuptools
' pkg_resources.require()
function:
>>> from pkg_resources import require >>> match = require("lxml") >>> match [lxml 3.3.0beta1 (/home/prologic/lib/python2.7/site-packages)] >>> lxml = match[0] >>> lxml.version '3.3.0beta1'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With