简体   繁体   English

无法在python2.7中安装lxml

[英]Can't install lxml in python2.7

Im trying to install lxml within a virtualenv with sudo pip install lxml and also sudo pip install --upgrade lxml but getting the following in both cases: 我试图在一个virtualenv中安装lxml与sudo pip install lxml以及sudo pip install --upgrade lxml但在以下两种情况下获得以下内容:

x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,
relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes    
-D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat 
-Werror=format-security build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -lxslt 
-lexslt -lxml2 -lz -lm -o build/lib.linux-x86_64-2.7/lxml/etree.so

/usr/bin/ld: cannot find -lz

collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, 
tokenize;__file__='/tmp/pip_build_root/lxml/setup.py';
exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), 
__file__, 'exec'))" install --record /tmp/pip-nmFOYf-record/install-record.txt 
--single-version-externally-managed --compile failed with error code 1 in 
/tmp/pip_build_root/lxml
Storing debug log for failure in /root/.pip/pip.log

I have tried all the posted solutions here , which implies that I have libxml2-dev , libxslt-dev and python-dev installed and I also installed build-essential 我在这里尝试了所有发布的解决方案,这意味着我安装了libxml2-devlibxslt-devpython-dev并且我还安装了build-essential
I'm currently running Linux Mint 17 Debian Based which uses apt-get as package manager. 我目前正在运行Linux Mint 17 Debian Based,它使用apt-get作为包管理器。
python-lxml was already preinstalled. python-lxml已经预装好了。

lxml depends on various C libraries, and you have to have those C libraries installed—including their development files (headers, .so or .a libraries, etc.)—to build lxml . lxml依赖于各种C库,你必须安装这些C库 - 包括它们的开发文件(头文件, .so.a库等) - 来构建lxml The installation docs explain what prerequisites you need to build on your particular platform. 安装文档说明了在特定平台上构建所需的先决条件。


This error: 这个错误:

/usr/bin/ld: cannot find -lz

… means that the prerequisite you're missing is libz , aka zlib . ...意味着您缺少的先决条件是libz ,也就是zlib

Since you're not on Windows, it's incredibly unlikely that you actually don't have zlib at all… but pretty plausible that you don't have the development files for zlib . 因为你不在Windows上,所以你实际上根本没有zlib是非常不可能的......但是你没有zlib的开发文件是相当合理的。 On some platforms, most notably many linux distros, packages are typically split into separate pieces. 在某些平台上,最值得注意的是许多Linux发行版,软件包通常分成不同的部分。 For example, the parts of zlib needed at runtime may be in a package named zlib , while the parts needed for building other programs that need zlib in a package named zlib-dev or zlib-devel . 例如,运行时所需的zlib部分可能位于名为zlib的包中,而在名为zlib-devzlib-devel的包中构建需要zlib其他程序所需的部分。 The exact details depend on your exact platform. 具体细节取决于您的确切平台。

That being said, if you don't have the zlib development files, you probably don't have the libxml2 or libxslt development files either, because I don't know of any platform where installing those wouldn't have pulled in the zlib files as well. 话虽这么说,如果你没有zlib开发文件,你可能也没有libxml2libxslt开发文件,因为我不知道任何平台安装那些不会拉入zlib文件同样。

At any rate, since you haven't told us what platform you're one (and distro, if linux), I don't know what package manager to use, what the packages are named, etc., but do whatever's appropriate for your platform. 无论如何,既然你没有告诉我们你是一个平台(和发行版,如果是linux),我不知道要使用什么包管理器,包命名是什么等等,但做任何适合的你的平台。


Also: 也:

I already have python-lxml installed 我已经安装了python-lxml

You really shouldn't install the same package both with your distro's package manager and with pip ; 你真的不应该用你的发行包管理器和pip安装相同的包; that's a great way to confuse yourself. 这是混淆自己的好方法。

But at any rate, most likely you installed python-lxml from a binary package, not from source, which means you didn't need the build requirements. 但无论如何,很可能你从二进制包而不是源代码安装python-lxml ,这意味着你不需要构建要求。 Now you're trying to build it from source, which means you do. 现在你正在尝试从源代码构建它,这意味着你可以。

在基于ubuntu的Linux发行版上,您可以使用:

sudo apt-get install zlib1g-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM