gpt4 book ai didi

python - ubuntu 上的 lxml 3.1.2 和 lxml2

转载 作者:太空宇宙 更新时间:2023-11-04 03:53:45 32 4
gpt4 key购买 nike

我想在我的 ubuntu 12.04 上安装 lxml 3.1.2。它已经通过包管理器安装了 lxml2。有没有人已经成功完成了 lxml 的双重安装?

我有 pip 担心我的安装困惑,主要是因为我的安装看起来很困惑!

我阅读了文档:

Using lxml with python-libxml2

If you want to use lxml together with the official libxml2 Python bindings (maybe because one of your dependencies uses it), you must build lxml statically. Otherwise, the two packages will interfere in places where the libxml2 library requires global configuration, which can have any kind of effect from disappearing functionality to crashes in either of the two. To get a static build, either pass the --static-deps option to the setup.py script, or run pip with the STATIC_DEPS or STATICBUILD environment variable set to true, i.e. STATIC_DEPS=true pip install lxml The STATICBUILD environment variable is handled equivalently to the STATIC_DEPS variable, but is used by some other extension packages, too.

所以我准备好运行了

STATIC_DEPS=true pip install lxml

但是我犹豫了。假设这可行,我如何在 python 程序中区分我使用的是哪个 lxml?

import lxml 

会得到哪个 lxml?

现在,pip freeze lxml 给我 lxml==2.3.2

我现在不知道那是来自 pip 安装还是来自 ubuntu 包...

使用 dpkg -L python-lxml,我得到了很多文件,其中有:

> /usr/lib/python2.7/dist-packages/lxml-2.3.2.egg-info/not-zip-safe
> /usr/lib/python2.7/dist-packages/lxml-2.3.2.egg-info/SOURCES.txt
> /usr/lib/python2.7/dist-packages/lxml-2.3.2.egg-info/dependency_links.txt
> /usr/lib/python2.7/dist-packages/lxml-2.3.2.egg-info/top_level.txt
> /usr/lib/python2.7/dist-packages/lxml-2.3.2.egg-info/PKG-INFO

还有:

> /usr/share/pyshared/lxml-2.3.2.egg-info
> /usr/share/pyshared/lxml-2.3.2.egg-info/not-zip-safe
> /usr/share/pyshared/lxml-2.3.2.egg-info/SOURCES.txt
> /usr/share/pyshared/lxml-2.3.2.egg-info/dependency_links.txt
> /usr/share/pyshared/lxml-2.3.2.egg-info/top_level.txt
> /usr/share/pyshared/lxml-2.3.2.egg-info/PKG-INF

当我使用 lxml 时,它来自其中的哪一个(或其他地方?)?

神秘!

最佳答案

运行时可以查到加载了哪个lxml

$ python -c "import lxml; print lxml.__file__"

如果你想使用同一个包的多个版本,你可能会找到virtualenv有用。事实上,即使没有这个条件,它也很有用。

为了简化虚拟环境的使用,您可能想使用 virtualenvwrapper .然后你可以简单地切换:

$ workon lxml232
(lxml232) $ python -c "import lxml.etree; print lxml.etree.__version__"
2.3.2
(lxml232) $ workon lxm312
(lxml312) $ python -c "import lxml.etree; print lxml.etree.__version__"
3.1.2

关于python - ubuntu 上的 lxml 3.1.2 和 lxml2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19852911/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com