如何在 Ubuntu 上安装 lxml

发布于 2024-11-17 18:02:11 字数 2232 浏览 2 评论 0原文

我在 Ubuntu 11 上使用 easy_install 安装 lxml 时遇到困难。

当我输入 $ easy_install lxml 时,我得到:

Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3
Downloading http://lxml.de/files/lxml-2.3.tgz
Processing lxml-2.3.tgz
Running lxml-2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-7UdQOZ/lxml-2.3/egg-dist-tmp-GacQGy
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt 
In file included from src/lxml/lxml.etree.c:227:0:
src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory
compilation terminated.

看来 libxsltlibxml2 是未安装。我尝试按照 http://www.techsww.com 中的说明进行操作/tutorials/libraries/libxslt/installation/installing_libxslt_on_ubuntu_linux.phphttp://www.techsww.com/tutorials/libraries/libxml/installation/installing_libxml_on_ubuntu_linux .php 没有成功。

如果我尝试 wget ftp://xmlsoft.org/libxml2/libxml2-sources-2.6.27.tar.gz 我得到

<successful connection info>
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /libxml2 ... done.
==> SIZE libxml2-sources-2.6.27.tar.gz ... done.
==> PASV ... done.    ==> RETR libxml2-sources-2.6.27.tar.gz ... 
No such file `libxml2-sources-2.6.27.tar.gz'.

If I try other first, I'll get to . /configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2 最终会失败:

checking for libxml libraries >= 2.6.27... configure: error: Could not find libxml2 anywhere, check ftp://xmlsoft.org/.

我已经尝试了两个版本libxml22.6.272.6.29 没有区别。

我不遗余力地成功完成了sudo apt-get install libxml2-dev,但这没有任何改变。

I'm having difficulty installing lxml with easy_install on Ubuntu 11.

When I type $ easy_install lxml I get:

Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3
Downloading http://lxml.de/files/lxml-2.3.tgz
Processing lxml-2.3.tgz
Running lxml-2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-7UdQOZ/lxml-2.3/egg-dist-tmp-GacQGy
Building lxml version 2.3.
Building without Cython.
ERROR: /bin/sh: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt 
In file included from src/lxml/lxml.etree.c:227:0:
src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h: No such file or directory
compilation terminated.

It seems that libxslt or libxml2 is not installed. I've tried following the instructions at http://www.techsww.com/tutorials/libraries/libxslt/installation/installing_libxslt_on_ubuntu_linux.php and http://www.techsww.com/tutorials/libraries/libxml/installation/installing_libxml_on_ubuntu_linux.php with no success.

If I try wget ftp://xmlsoft.org/libxml2/libxml2-sources-2.6.27.tar.gz I get

<successful connection info>
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /libxml2 ... done.
==> SIZE libxml2-sources-2.6.27.tar.gz ... done.
==> PASV ... done.    ==> RETR libxml2-sources-2.6.27.tar.gz ... 
No such file `libxml2-sources-2.6.27.tar.gz'.

If I try the other first, I'll get to ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2 and that will fail eventually with:

checking for libxml libraries >= 2.6.27... configure: error: Could not find libxml2 anywhere, check ftp://xmlsoft.org/.

I've tried both versions 2.6.27 and 2.6.29 of libxml2 with no difference.

Leaving no stone unturned, I have successfully done sudo apt-get install libxml2-dev, but this changes nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

为你鎻心 2024-11-24 18:02:11

由于您使用的是 Ubuntu,因此不必理会那些源代码包。只需使用 apt-get 安装这些开发包即可。

apt-get install libxml2-dev libxslt1-dev python-dev

如果您对 lxml 的旧版本感到满意,您可以尝试

apt-get install python-lxml

使用它。 :)

Since you're on Ubuntu, don't bother with those source packages. Just install those development packages using apt-get.

apt-get install libxml2-dev libxslt1-dev python-dev

If you're happy with a possibly older version of lxml altogether though, you could try

apt-get install python-lxml

and be done with it. :)

一个人的夜不怕黑 2024-11-24 18:02:11

我还必须在 lxml 编译之前安装 lib32z1-dev (Ubuntu 13.04 x64)。

sudo apt-get install lib32z1-dev

或者将所有必需的包放在一起:

sudo apt-get install libxml2-dev libxslt-dev python-dev lib32z1-dev

I also had to install lib32z1-dev before lxml would compile (Ubuntu 13.04 x64).

sudo apt-get install lib32z1-dev

Or all the required packages together:

sudo apt-get install libxml2-dev libxslt-dev python-dev lib32z1-dev
或十年 2024-11-24 18:02:11

正如@Pepijn评论@Druska的答案,在ubuntu 13.04 x64上,不需要使用lib32z1-dev,zlib1g-dev就足够了:

sudo apt-get install libxml2-dev libxslt-dev python-dev zlib1g-dev

As @Pepijn commented on @Druska 's answer, on ubuntu 13.04 x64, there is no need to use lib32z1-dev, zlib1g-dev is enough:

sudo apt-get install libxml2-dev libxslt-dev python-dev zlib1g-dev
﹎☆浅夏丿初晴 2024-11-24 18:02:11

我使用 Ubuntu 14.04 在 Vagrant 中使用 pip 安装了 lxml 并遇到了同样的问题。尽管安装了所有要求,我还是一次又一次地遇到相同的错误。结果,默认情况下我的虚拟机内存很少。 1024 MB 一切正常。

将其添加到您的 VagrantFile 中,lxml 应该正确编译/安装:

config.vm.provider "virtualbox" do |vb|
  vb.memory = 1024
end

感谢 Sixhobbit 的提示(请参阅:无法在 Ubuntu 12.04 上安装 lxml)。

I installed lxml with pip in Vagrant, using Ubuntu 14.04 and had the same problem. Even though all requirements where installed, i got the same error again and again. Turned out, my VM had to little memory by default. With 1024 MB everything works fine.

Add this to your VagrantFile and lxml should properly compile / install:

config.vm.provider "virtualbox" do |vb|
  vb.memory = 1024
end

Thanks to sixhobbit for the hint (see: can't installing lxml on Ubuntu 12.04).

若无相欠,怎会相见 2024-11-24 18:02:11

第 1 步

使用此命令安装最新的 python 更新。

sudo apt-get install python-dev

第 2 步

添加第一个依赖项libxml2版本2.7.0或更高版本

sudo apt-get install libxml2-dev

第3步

添加第二个依赖项libxslt版本1.1.23或更高版本

sudo apt-get install libxslt1-dev

步骤4

首先安装pip包管理工具。并运行此命令。

pip 安装 lxml

如果您有任何疑问点击此处

Step 1

Install latest python updates using this command.

sudo apt-get install python-dev

Step 2

Add first dependency libxml2 version 2.7.0 or later

sudo apt-get install libxml2-dev

Step 3

Add second dependency libxslt version 1.1.23 or later

sudo apt-get install libxslt1-dev

Step 4

Install pip package management tool first. and run this command.

pip install lxml

If you have any doubt Click Here

(り薆情海 2024-11-24 18:02:11

对于 Ubuntu 14.04

sudo apt-get install python-lxml

对我有用。

For Ubuntu 14.04

sudo apt-get install python-lxml

worked for me.

故人如初 2024-11-24 18:02:11

安装 AKX 提到的软件包后我仍然遇到同样的问题。解决了它

apt-get install python-dev

After installing the packages mentioned by AKX I still had the same problem. Solved it with

apt-get install python-dev
驱逐舰岛风号 2024-11-24 18:02:11

对于 Ubuntu 12.04.3 LTS(精确穿山甲),我必须这样做:(

apt-get install libxml2-dev libxslt1-dev

注意 libxslt1-dev 中的“1”)

然后我刚刚使用 pip/easy_install 安装了 lxml。

For Ubuntu 12.04.3 LTS (Precise Pangolin) I had to do:

apt-get install libxml2-dev libxslt1-dev

(Note the "1" in libxslt1-dev)

Then I just installed lxml with pip/easy_install.

蓝咒 2024-11-24 18:02:11

从 Ubuntu 18.4 (Bionic Beaver) 开始,建议使用 apt 而不是 apt-get,因为它具有更好的结构形式。

sudo apt install libxml2-dev libxslt1-dev python-dev

如果您对旧版本的 lxml 感到满意,您可以尝试

sudo apt install python-lxml

From Ubuntu 18.4 (Bionic Beaver) it is advisable to use apt instead of apt-get since it has much better structural form.

sudo apt install libxml2-dev libxslt1-dev python-dev

If you're happy with a possibly older version of lxml altogether though, you could try

sudo apt install python-lxml
负佳期 2024-11-24 18:02:11

这里的许多答案都相当旧,
感谢@Simplans (https://stackoverflow.com/a/37759871/417747) 的指针和主页...

什么对我有用(Ubuntu仿生):

sudo apt-get install python3-lxml  

(+ sudo apt-get install libxml2-dev libxslt1-dev 我之前安装过,但不确定这是否仍然是要求)

Many answers here are rather old,
thanks to the pointer from @Simplans (https://stackoverflow.com/a/37759871/417747) and the home page...

What worked for me (Ubuntu bionic):

sudo apt-get install python3-lxml  

(+ sudo apt-get install libxml2-dev libxslt1-dev I installed before it, but not sure if that's the requirement still)

俏︾媚 2024-11-24 18:02:11

首先安装 Ubuntu 的 python-lxml 软件包及其依赖项:

sudo apt-get install python-lxml

然后使用 pip 升级到 Python 的 lxml 最新版本:

pip install lxml

First install Ubuntu's python-lxml package and its dependencies:

sudo apt-get install python-lxml

Then use pip to upgrade to the latest version of lxml for Python:

pip install lxml
这样的小城市 2024-11-24 18:02:11

您可以按照以下步骤在 Ubuntu 上安装 lxml:

  • 在 Ubuntu 系统上打开终端。

  • 通过运行以下命令更新包列表:

     sudo apt-get update
    
  • 通过运行以下命令安装所需的依赖项:

     sudo apt-get install libxml2-dev libxslt-dev python-dev
    
  • 通过运行以下命令安装 lxml:

     sudo pip install lxml
    
  • 如果您没有安装pip,可以通过运行以下命令安装它:

     sudo apt-get install python-pip
    
  • 通过运行以下命令验证 lxml 是否已安装:

     python -c "导入 lxml; print(lxml.__version__)"
    

这应该输出您刚刚安装的 lxml 的版本号。

就是这样!

You can install lxml on Ubuntu by following these steps:

  • Open the terminal on your Ubuntu system.

  • Update the package list by running the following command:

     sudo apt-get update
    
  • Install the required dependencies by running the following command:

     sudo apt-get install libxml2-dev libxslt-dev python-dev
    
  • Install lxml by running the following command:

     sudo pip install lxml
    
  • If you don't have pip installed, you can install it by running the following command:

     sudo apt-get install python-pip
    
  • Verify that lxml is installed by running the following command:

     python -c "import lxml; print(lxml.__version__)"
    

This should output the version number of lxml that you just installed.

That's it!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文