cannot Install libxml2 in virtualenv

泄露秘密 提交于 2020-01-14 12:02:02

问题


I have got an issue with libxml2 python module.

I'm trying to install it on a python3 virtualenv using the following command:

pip install libxml2-python3

but it shows the following error:

Collecting libxml2-python3   Using cached
https://files.pythonhosted.org/packages/41/97/a2ecf6c5b291799dbd40b3d041d89b0ecdb1b43c8c2503e27991325851cd/libxml2-python3-2.9.5.tar.gz
     Complete output from command python setup.py egg_info:
     failed to find headers for libxml2: update includes_dir

     ---------------------------------------- 
 Command "python setup.py egg_info" failed with error code 1 in
 /tmp/pip-install-72u9ke0y/libxml2-python3/

I tried the solutions provided in the following links but nothing works for me :

https://github.com/GoogleCloudPlatform/google-cloud-python/issues/3884

"pip install unroll": "python setup.py egg_info" failed with error code 1

How to install libxml2 in virtualenv?

i work on fedora 27 os


回答1:


If I'm not mistaken, you would need the libxml2 development files. Try running

yum install libxml2-devel

then run the pip install again




回答2:


It's installed with lxml, in fact you probably want to use lxml instead of libxml2 because lxml is based on libxml2 is more pythonic:

sudo pip install lxml

libxml2 page says:

Note that some of the Python purist dislike the default set of Python bindings, rather than complaining I suggest they have a look at lxml the more pythonic bindings for libxml2 and libxslt and check the mailing-list.

lxml page says:

The lxml XML toolkit is a Pythonic binding for the C libraries libxml2 and libxslt. It is unique in that it combines the speed and XML feature completeness of these libraries with the simplicity of a native Python API, mostly compatible but superior to the well-known ElementTree API. The latest release works with all CPython versions from 2.6 to 3.6. See the introduction for more information about background and goals of the lxml project. Some common questions are answered in the FAQ.




回答3:


Yeah, I got the same error after trying to update the lmxl pip package. The problem is that lxml depends on both libmxl2 and libxslt development libraries. Therefore you need to make sure they are installed first.

# pip3 show lxml
Name: lxml
Version: 4.2.5
Summary: Powerful and Pythonic XML processing library combining libxml2/libxslt with the ElementTree API.
Home-page: http://lxml.de/
Author: lxml dev team
Author-email: lxml-dev@lxml.de
License: BSD
Location: /usr/lib/python3.6/site-packages
Requires:
Required-by: Scrapy, parsel, [etc etc]

So install the packages along the line with:

apt-get install libxml2-devel libxslt-devel

(And whatever they depend on in turn.)




回答4:


I hit similar situation, my linux is Ubuntu on Windows 10 (WSL - Windows Subsystem for Linux)

What I did to solve the issue is:

  1. Using apt, install: python3 python3-pip, libxml2 libxml2-dev.
me@WSL:~/$ sudo apt-get update
me@WSL:~/$ sudo apt install python3 python3-pip libxml2 libxml2-dev
  1. Using installed pip, install libxml2-python
    me@WSL:~/$ pip3 install libxml2-python3
  1. done. hope this notes help you.


来源:https://stackoverflow.com/questions/50880914/cannot-install-libxml2-in-virtualenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!