为什么我不能让 `pip install lxml` 在 vi​​rtualenv 中工作? [英] Why can't I get `pip install lxml` to work within a virtualenv?

查看:18
本文介绍了为什么我不能让 `pip install lxml` 在 vi​​rtualenv 中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我使用的是 virtualenvwrapper.

在激活虚拟环境之前:

$ pip install lxml需求已经满足(使用--upgrade升级):/usr/lib/python2.7/dist-packages中的lxml打扫干净...

激活虚拟环境后:

(test-env)$ pip install lxmlforce/build/lxml/src/lxml/includes/etree_defs.h:9:31: 致命错误:libxml/xmlversion.h:没有那个文件或目录编译终止.错误:命令gcc"失败,退出状态为 1---------------------------命令/home/chaz/dev/envs/test-with-system-python-force/bin/python2.7 -c "import setuptools;__file__='/home/chaz/dev/envs/test-with-system-python-force/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record/tmp/pip-bJ6Q_B-record/install-record.txt --single-version-externally-managed --install-headers/home/chaz/dev/envs/test-env/include/site/python2.7 失败,错误代码为 1/home/chaz/dev/envs/test-env/build/lxml将完整的日志存储在/home/chaz/.pip/pip.log

解决方案

您可能已经在您的系统上安装了 lxml,可能是由于系统包而安装的.因此,第一次尝试(pip install lxml 没有活动的 virtualenv)不会失败,但它也不会安装它;它真的没有做任何事情.

在 virtualenv 中,默认情况下,系统包被忽略.所以pip认为没有安装lxml.因此,它会尝试将其安装到您的虚拟环境中.

lxml 包含需要编译才能正确安装的 C 模块.但是,这些 C 模块的编译依赖于您已经安装了一些开发库".这些开发库是 C 库,而不是 Python,因此 pip 无法自动从 Internet 获取它们并为您安装.

因此,您需要自己安装这些开发库,很可能使用您的包管理器.在 Debian 系统(如 Ubuntu)中,这是...

apt-get install libxml2-dev libxslt-dev

这会将 libxml2 和 libxslt 开发库安装到您的本地系统.如果您再次尝试安装 lxml,C 模块编译步骤应该可以工作,因为现在这些开发库已在您的系统上.

您收到的错误消息是由于缺少这些库(错误消息的 libxml/xmlversion.h: No such file or directory 部分).

另见:如何在 Ubuntu 上安装 lxml

Note: I'm using virtualenvwrapper.

Before activating the virtual environment:

$ pip install lxml
Requirement already satisfied (use --upgrade to upgrade): lxml in /usr/lib/python2.7/dist-packages  
Cleaning up...  

After activating the virtual environment:

(test-env)$ pip install lxml
force/build/lxml/src/lxml/includes/etree_defs.h:9:31: fatal error: 
libxml/xmlversion.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /home/chaz/dev/envs/test-with-system-python-force/bin/python2
.7 -c "import setuptools;__file__='/home/chaz/dev/envs/test-with-
system-python-force/build/lxml/setup.py';exec(compile(open(__file__).
read().replace('\r\n', '\n'), __file__, 'exec'))" install --record 
/tmp/pip-bJ6Q_B-record/install-record.txt --single-version-externally
-managed --install-headers /home/chaz/dev/envs/test-env/include/site/python2.7 failed with error code 1 in 
/home/chaz/dev/envs/test-env/build/lxml
Storing complete log in /home/chaz/.pip/pip.log

解决方案

You probably already have lxml installed on your system, perhaps installed due to a system package. Thus, the first attempt (pip install lxml without an active virtualenv) doesn't fail, but it also doesn't install it; it really doesn't do anything.

In a virtualenv, by default, the system packages are ignored. Therefore, pip thinks that lxml is not installed. Therefore, it tries to install it into your virtual environment.

lxml contains C modules that need to be compiled in order to install properly. However, the compilation of those C modules rely on your having some "development libraries" already installed as well. These development libraries are C libraries, not Python, and as such pip won't be able to automatically fetch them from the internet and install them for you.

Therefore, you will need to install these development libraries on your own, most likely using your package manager. In a Debian system (like Ubuntu), this is...

apt-get install libxml2-dev libxslt-dev

This will install the libxml2 and libxslt development libraries to your local system. If you try again to install lxml, the C module compilation step should work because now these development libraries are on your system.

The error message you were receiving was due to the fact that these libraries were missing (the libxml/xmlversion.h: No such file or directory part of the error message).

See also: How to install lxml on Ubuntu

这篇关于为什么我不能让 `pip install lxml` 在 vi​​rtualenv 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆