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
?
问题:
回答1:
pip install ftp://xmlsoft.org/libxml2/python/libxml2-python-2.6.9.tar.gz
回答2:
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
回答3:
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
回答4:
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
.
回答5:
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.
回答6:
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.