标签归档:libxml2

如何在Ubuntu上安装LXML

问题:如何在Ubuntu上安装LXML

我在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.

看来libxslt还是libxml2没有安装。我已经尝试按照http://www.techsww.com/tutorials/libraries/libxslt/installation/installing_libxslt_on_ubuntu_linux.phphttp://www.techsww.com/tutorials/libraries/libxml/installation/installing_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'.

如果我先尝试另一种,那我会做的,./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/.

我试过两个版本2.6.272.6.29libxml2没什么区别。

不遗余力,我已经成功完成了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.


回答 0

由于您使用的是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. :)


回答 1

在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

回答 2

正如@Pepijn在ubuntu 13.04 x64上评论@Druska的答案一样,无需使用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

回答 3

我使用Ubuntu 14.04在Vagrant中使用pip安装了lxml,并且遇到了同样的问题。即使安装了所有要求,我也一次又一次遇到相同的错误。事实证明,默认情况下,我的VM的内存很少。有了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).


回答 4

对于Ubuntu 14.04

sudo apt-get install python-lxml

为我工作。

For Ubuntu 14.04

sudo apt-get install python-lxml

worked for me.


回答 5

步骤1

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

sudo apt-get install python-dev

第2步

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

sudo apt-get install libxml2-dev

第三步

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

sudo apt-get install libxslt1-dev

第四步

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

pip install 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


回答 6

安装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

回答 7

对于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.


回答 8

从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

回答 9


由于@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)


回答 10

首先安装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