I have virtualenv with --no-site-packages
option. I'm using scrapy in it. Scrapy uses libxml2 by import libxml2
. How to install libxml2 in virtualenv using pip
or easy_install
?
6 Answers
-
1for latest version xmlsoft.org/libxml2/python/libxml2-python-2.6.21.tar.gz Jun 4, 2012 at 12:05
-
1I got this error:failed to find headers for libxml2: update includes_dir– DanfiJul 20, 2012 at 1:40
-
2@Danfi: You still need to install libxml2 and its headers:
sudo apt-get install libxml2 libxml2-dev
Jul 30, 2012 at 11:54 -
Anyone know how I can place this link in my requirements.txt? I'm getting an error when doing -e ftp://... Nov 8, 2013 at 20:08
-
1pip uses requests which does not support FTP. stackoverflow.com/questions/15115328/… - use this url: xmlsoft.org/sources/python/libxml2-python-2.6.21.tar.gz Jul 8, 2014 at 12:01
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
-
1Pretty sure the OP was referring to the Python package called "libxml2", i.e. "import libxml2" not the C library (which the python package wraps). Dec 18, 2013 at 12:58
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
-
I had to use
libxslt-dev
instead oflibxslt1-dev
Ubuntu 12.04 Python 2.7.3– anglinbDec 18, 2014 at 21:06 -
Yes, this is trues also for Cygwin (Fedora), only the development headers are called
libxml2-devel
andlibxslt-devel
. And yes, uselxml
, instead. Nov 8, 2018 at 15:50
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
.
-
The reason that worked, is probably because that operation also installed the development libraries of
libxml2-dev
andlibxslt-dev
, which is the most common cause for pip install problems withlxml
. Nov 8, 2018 at 15:53
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.
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.