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:
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
I'm currently running Linux Mint 17 Debian Based which uses apt-get
as package manager.python-lxml
was already preinstalled.
Open your Linux terminal or shell. Type “ pip install lxml ” (without quotes), hit Enter. If it doesn't work, try "pip3 install lxml" or “ python -m pip install lxml “.
In case you want to use the current in-development version of lxml, you can get it from the github repository at https://github.com/lxml/lxml .
lxml has been downloaded from the Python Package Index millions of times and is also available directly in many package distributions, e.g. for Linux or macOS.
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
. 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
.
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
. On some platforms, most notably many linux distros, packages are typically split into separate pieces. 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
. 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.
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.
Also:
I already have
python-lxml
installed
You really shouldn't install the same package both with your distro's package manager and with 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. Now you're trying to build it from source, which means you do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With