如何在 virtualenv 中安装 libxml2?

发布于 2024-09-26 04:20:26 字数 225 浏览 0 评论 0原文

我有 virtualenv--no-site-packages 选项。我在其中使用scrapy。 Scrapy 通过 import libxml2 使用 libxml2。如何使用 pipeasy_install 在 vi​​rtualenv 中安装 libxml2?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

尴尬癌患者 2024-10-03 04:20:26

libxml2 是一个 C 库而不是 python 包,因此您无法使用 Pip 来安装它。通常它已经安装在几乎每个 Linux 发行版上。如果您需要安装它,只需

sudo apt-get install libxml2

如果由于某种原因您绝对需要进行本地安装,您将需要获取并安装 .deb 软件包或 RPM。除非您可以下载源代码并构建它。

如果您可以使用通用副本,但不想在路径中包含 /usr/local/ ,那么只需在您的 virtualenv 中对其进行符号链接即可。

您可以在 http://xmlsoft.org/ 找到更多信息(比您可能想要的更多)

Scrapy 在其要求中列出了它:

  • Python 2.5 或更高版本
  • Twisted 2.5.0 或更高版本
  • libxml2 2.6.28 或更高版本(包括 Python bidings)
  • pyopenssl - 仅当您想要抓取安全(HTTPS)页面时

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
眼角的笑意。 2024-10-03 04:20:26

安装 lxml 之前(在 Debian 上):

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

其中 pythonX.Xpython2.7python2.6 或其他针刺 python 版本。

安装系统包后:

workon %environment_name%
pip install lxml --upgrade

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
两相知 2024-10-03 04:20:26

我刚刚使用 Ubuntu 14.04 内核遇到这个问题。

我已经使用 pip 安装了 lxml。

当我尝试在 virtualenv 中 pip install lxml --upgrade 时,它总是给我一个

x86_64-gnu-gcc 退出 1

我使用 sudo apt-get install libssl-dev 解决了这个问题。

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.

反话 2024-10-03 04:20:26

或者,如果你在 Windows 上,正如我从你的问题中怀疑的那样,你需要获取 libxml2 二进制文件——scrapy 网站上有链接,并且截至 2010 年 11 月,已经编译了一个可以与所有内容一起使用的版本—— - 或者获取 scrapy 的当前 trunk/dev 版本,它与 lxml2 一起使用。对于 virtualenv,由于我不确定如何使用额外的二进制文件进行设置,因此后一种方法可能是最好的。我采用了后一种方法,到目前为止它对我来说完美无缺。感谢 Pablo Hoffman,Scrapy 的超级乐于助人的创建者(当我在 Scrapy 的邮件列表上发布一个与此非常相似的问题时,他几乎第二天就将这一更改发布到了主干)。注意:当时还没有与 python 2.7 一起使用的 libxml2 二进制文件。

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.

短暂陪伴 2024-10-03 04:20:26

如果您使用 apt-get(或其他包管理器)安装了 python-libxml2,您可以使用 --system-site-packages 标志从 virtualenv 访问它。

创建 virtualenv 时只需指定此标志,例如:

virtualenv --system-site-packages env

这样您的 virtualenv 将继承系统范围内安装的 libxml2 包。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文