Cannot install lxml in python2.7

I am trying to install lxml inside virtualenv using sudo pip install lxml as well as 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 tried all the published solutions here , which implies that I have installed libxml2-dev , libxslt-dev and python-dev , and I also installed build-essential
I am currently running Linux Mint 17 Debian Based, which uses apt-get as its package manager.
python-lxml already preinstalled.

+5
source share
2 answers

lxml depends on different C libraries, and you must have these C libraries installed, including their development files (headers, .so or .a , etc.) to build lxml . The installation documents explain what prerequisites you need to create on your particular platform.


This error:

 /usr/bin/ld: cannot find -lz 

... means the prerequisite is libz , aka zlib .

Since you're not on Windows, it is incredibly unlikely that you actually don't have zlib at all ... but it's pretty likely that you don't have development files for zlib . On some platforms, especially most Linux distributions, packages are usually divided into separate parts. For example, the parts of zlib needed at run time may be in a package named zlib , and the parts needed to create other programs that require zlib in a package named zlib-dev or zlib-devel . The exact details depend on your exact platform.

If you do not have zlib development files, you probably do not have libxml2 or libxslt development files, because I do not know of any platform on which I would not pull zlib files.

In any case, since you did not tell us which platform you have one (and the distribution, if linux), I do not know which package manager to use, what package names, etc., but no matter what suits your platforms.


also:

I already have python-lxml

You really should not install the same package with either your distribution package manager or pip ; what a great way to confuse yourself.

But, in any case, most likely you installed python-lxml from a binary package and not from the source, which means that you do not need assembly requirements. Now you are trying to build it from the source, which means that you are doing it.

+7
source

On a ubuntu-based Linux distribution, you can use:

sudo apt-get install zlib1g-dev

+3
source

Source: https://habr.com/ru/post/1204686/


All Articles