How to install libxml2 in virtualenv?

喜欢而已 提交于 2019-11-29 01:49:50

libxml2 is a C library not a python package so you cannot use Pip to install it. Normally it is already installed on almost every Linux distro out there. If you need to install it it's just

sudo apt-get install libxml2

If for some reason you absolutely need to have a local install you will need to grab and install the .deb package or the RPM. Barring that you can download the source and build it.

If you are fine with using the common copy but don't want to have /usr/local/ in your path, then just symlink it within your virtualenv.

You can find more info (than you probably wanted) at http://xmlsoft.org/

Scrapy lists it in their requirements:

  • Python 2.5 or Above
  • Twisted 2.5.0 or above
  • libxml2 2.6.28 or above (including Python bidings)
  • pyopenssl - only if you want to crawl secure (HTTPS) pages

Before install lxml (on Debian):

apt-get install libxml2-dev libxslt1-dev pythonX.X-dev -y

Where pythonX.X is python2.7 or python2.6 or other needled python version.

After install system packages:

workon %environment_name%
pip install lxml --upgrade
shwsun

I have just come to this problem, with Ubuntu 14.04 kernel.

I already installed lxml using pip.

When I try to pip install lxml --upgrade inside the virtualenv, it always gave me a

x86_64-gnu-gcc exit 1

I solved this using sudo apt-get install libssl-dev.

Alternatively, if you are on windows, as I suspect from your question, you need to either get the libxml2 binary-- there are links on the scrapy site, and as of Nov 2010, a version has been compiled that will work with everything-- or get the current trunk/dev version of scrapy, which works with lxml2. For virtualenv, since I'm not sure how to setup with an extra binary, the latter approach might be best. I've adopted the latter approach and it works flawlessly for me so far. Thanks to Pablo Hoffman the ultra-helpful creator of Scrapy (when I posted a question much like this one on Scrapy's mailing list, he released this change to trunk almost the next day). Note: libxml2 binary that worked with python 2.7 wasn't yet available at that time.

ApriOri

If you installed python-libxml2 using apt-get (or other package manager) you can access it from virtualenv with the --system-site-packages flag.

When creating your virtualenv just specify this flag, e.g:

virtualenv --system-site-packages env

This way your virtualenv will inherit the libxml2 package which is installed system wide.

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