Find python lxml version

前端 未结 6 1634
Happy的楠姐
Happy的楠姐 2021-02-03 18:32

How can I find the installed python-lxml version in a Linux system?

>>> import lxml
>>> lxml.__version__
Traceback (most recent call last):
  F         


        
6条回答
  •  面向向阳花
    2021-02-03 18:57

    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'
    

提交回复
热议问题