如何在 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.php 和 http://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/.
我已经尝试了两个版本libxml2
的 2.6.27
和 2.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
由于您使用的是 Ubuntu,因此不必理会那些源代码包。只需使用 apt-get 安装这些开发包即可。
如果您对 lxml 的旧版本感到满意,您可以尝试
使用它。 :)
Since you're on Ubuntu, don't bother with those source packages. Just install those development packages using apt-get.
If you're happy with a possibly older version of lxml altogether though, you could try
and be done with it. :)
我还必须在 lxml 编译之前安装 lib32z1-dev (Ubuntu 13.04 x64)。
或者将所有必需的包放在一起:
I also had to install lib32z1-dev before lxml would compile (Ubuntu 13.04 x64).
Or all the required packages together:
正如@Pepijn评论@Druska的答案,在ubuntu 13.04 x64上,不需要使用lib32z1-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:
我使用 Ubuntu 14.04 在 Vagrant 中使用 pip 安装了 lxml 并遇到了同样的问题。尽管安装了所有要求,我还是一次又一次地遇到相同的错误。结果,默认情况下我的虚拟机内存很少。 1024 MB 一切正常。
将其添加到您的 VagrantFile 中,lxml 应该正确编译/安装:
感谢 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:
Thanks to sixhobbit for the hint (see: can't installing lxml on Ubuntu 12.04).
第 1 步
第 2 步
第3步
步骤4
如果您有任何疑问点击此处
Step 1
Step 2
Step 3
Step 4
If you have any doubt Click Here
对于 Ubuntu 14.04
sudo apt-get install python-lxml
对我有用。
For Ubuntu 14.04
sudo apt-get install python-lxml
worked for me.
安装 AKX 提到的软件包后我仍然遇到同样的问题。解决了它
After installing the packages mentioned by AKX I still had the same problem. Solved it with
对于 Ubuntu 12.04.3 LTS(精确穿山甲),我必须这样做:(
注意 libxslt1-dev 中的“1”)
然后我刚刚使用 pip/easy_install 安装了 lxml。
For Ubuntu 12.04.3 LTS (Precise Pangolin) I had to do:
(Note the "1" in libxslt1-dev)
Then I just installed lxml with pip/easy_install.
从 Ubuntu 18.4 (Bionic Beaver) 开始,建议使用 apt 而不是 apt-get,因为它具有更好的结构形式。
如果您对旧版本的
lxml
感到满意,您可以尝试From Ubuntu 18.4 (Bionic Beaver) it is advisable to use apt instead of apt-get since it has much better structural form.
If you're happy with a possibly older version of
lxml
altogether though, you could try这里的许多答案都相当旧,
感谢@Simplans (https://stackoverflow.com/a/37759871/417747) 的指针和主页...
什么对我有用(Ubuntu仿生):
(+
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 libxml2-dev libxslt1-dev
I installed before it, but not sure if that's the requirement still)首先安装 Ubuntu 的
python-lxml
软件包及其依赖项:然后使用
pip
升级到 Python 的 lxml 最新版本:First install Ubuntu's
python-lxml
package and its dependencies:Then use
pip
to upgrade to the latest version of lxml for Python:您可以按照以下步骤在 Ubuntu 上安装 lxml:
在 Ubuntu 系统上打开终端。
通过运行以下命令更新包列表:
通过运行以下命令安装所需的依赖项:
通过运行以下命令安装 lxml:
如果您没有安装pip,可以通过运行以下命令安装它:
通过运行以下命令验证 lxml 是否已安装:
这应该输出您刚刚安装的 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:
Install the required dependencies by running the following command:
Install lxml by running the following command:
If you don't have pip installed, you can install it by running the following command:
Verify that lxml is installed by running the following command:
This should output the version number of lxml that you just installed.
That's it!