首页 文章

使用pip在virtualenv中安装lxml Ubuntu 12.10错误:命令'gcc'失败,退出状态为4

提问于
浏览
35

当我尝试在Ubuntu 12.10 x64中运行“pip install lxml”进入virtualenv时,我遇到以下错误 . 我有Python 2.7 .

我在这里看到了有关同一问题的其他相关问题,并尝试安装python-dev,libxml2-dev和libxslt1-dev .

请查看从我发送命令的那一刻到发生错误的那一刻的追溯 .

Downloading/unpacking lxml
  Running setup.py egg_info for package lxml
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    Building lxml version 3.1.2.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    Building against libxml2/libxslt in the following directory: /usr/lib

    warning: no files found matching '*.txt' under directory 'src/lxml/tests'
Installing collected packages: lxml
  Running setup.py install for lxml
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
      warnings.warn(msg)
    Building lxml version 3.1.2.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    Building against libxml2/libxslt in the following directory: /usr/lib
    building 'lxml.etree' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/home/admin/.virtualenvs/dev.actualito.com/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o
    src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__getFilenameForFile':
    src/lxml/lxml.etree.c:26851:7: warning: variable '__pyx_clineno' set but not used [-Wunused-but-set-variable]
    src/lxml/lxml.etree.c:26850:15: warning: variable '__pyx_filename' set but not used [-Wunused-but-set-variable]
    src/lxml/lxml.etree.c:26849:7: warning: variable '__pyx_lineno' set but not used [-Wunused-but-set-variable]
    src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_4XSLT_18__call__':
    src/lxml/lxml.etree.c:138273:81: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default]
    src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
    src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__copyXSLT':
    src/lxml/lxml.etree.c:139667:79: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default]
    src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'
    src/lxml/lxml.etree.c: At top level:
    src/lxml/lxml.etree.c:12384:13: warning: '__pyx_f_4lxml_5etree_displayNode' defined but not used [-Wunused-function]
    gcc: internal compiler error: Killed (program cc1)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See  for instructions.
    error: command 'gcc' failed with exit status 4
    Complete output from command /home/admin/.virtualenvs/dev.actualito.com/bin/python -c "import setuptools;__file__='/home/admin/.virtualenvs/dev.actualito.com/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-asDtN5-record/install-record.txt --single-version-externally-managed --install-headers /home/admin/.virtualenvs/dev.actualito.com/include/site/python2.7:
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'

  warnings.warn(msg)

Building lxml version 3.1.2.

Building without Cython.

Using build configuration of libxslt 1.1.26

Building against libxml2/libxslt in the following directory: /usr/lib

running install

running build

running build_py

copying src/lxml/includes/lxml-version.h -> build/lib.linux-x86_64-2.7/lxml/includes

running build_ext

building 'lxml.etree' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/libxml2 -I/home/admin/.virtualenvs/dev.actualito.com/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o

src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__getFilenameForFile':

src/lxml/lxml.etree.c:26851:7: warning: variable '__pyx_clineno' set but not used [-Wunused-but-set-variable]

src/lxml/lxml.etree.c:26850:15: warning: variable '__pyx_filename' set but not used [-Wunused-but-set-variable]

src/lxml/lxml.etree.c:26849:7: warning: variable '__pyx_lineno' set but not used [-Wunused-but-set-variable]

src/lxml/lxml.etree.c: In function '__pyx_pf_4lxml_5etree_4XSLT_18__call__':

src/lxml/lxml.etree.c:138273:81: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default]

src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'

src/lxml/lxml.etree.c: In function '__pyx_f_4lxml_5etree__copyXSLT':

src/lxml/lxml.etree.c:139667:79: warning: passing argument 1 of '__pyx_f_4lxml_5etree_12_XSLTContext__copy' from incompatible pointer type [enabled by default]

src/lxml/lxml.etree.c:136229:52: note: expected 'struct __pyx_obj_4lxml_5etree__XSLTContext *' but argument is of type 'struct __pyx_obj_4lxml_5etree__BaseContext *'

src/lxml/lxml.etree.c: At top level:

src/lxml/lxml.etree.c:12384:13: warning: '__pyx_f_4lxml_5etree_displayNode' defined but not used [-Wunused-function]

gcc: internal compiler error: Killed (program cc1)

Please submit a full bug report,

with preprocessed source if appropriate.

See  for instructions.

error: command 'gcc' failed with exit status 4

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

7 回答

  • 2

    这是我保存的笔记 .

    sudo apt-get install libxml2
    sudo apt-get install libxslt1.1
    sudo apt-get install libxml2-dev
    sudo apt-get install libxslt1-dev
    sudo apt-get install python-libxml2
    sudo apt-get install python-libxslt1
    sudo apt-get install python-dev
    sudo apt-get install python-setuptools
    
    easy_install lxml
    

    它适用于我的ubuntu 12.10

  • 2

    确保你有足够的内存 . 试试 dmesg | tail ,看它是否输出如下:

    ...
    [3778136.277570] Out of memory: Kill process 21267 (cc1) score 557 or sacrifice child
    [3778136.277587] Killed process 21267 (cc1) total-vm:365836kB, anon-rss:336228kB, file-rss:0kB
    
  • 18

    根据lxml网站,你可以使用这样的结构:

    CFLAGS="-O0"  pip install lxml
    

    installation guide

    全局安装的注意事项:使用sudo传递环境变量的正确方法是 after sudo

    sudo CFLAGS="-O0" pip install lxml
    
  • 8

    今天早上我遇到了类似的问题(错误:命令'gcc'以退出状态4失败) . 看来你需要检查机器的内存 . 如果内存低于512M,那可能是原因 . 尝试暂时关闭一些服务,比如apache服务器,再次尝试“pip install lxml” . 它可能正常工作!

  • 25

    我偶然发现了这个问题 .

    Short answer

    Python2: $ python2.7 setup.py clean build --with-cython install
    Python3: $ pip-3.3 install lxml
    

    Long answer

    假设 pip install lxml 应该适用于每个环境,无论您使用的是Python2还是Python3 .

    还有 Cython 被考虑:由于相关的性能提升,您肯定会喜欢 lxml 编译 Cython .

    由于我不知道的原因,Python2上的编译找不到Cython . 为了更准确和绝对明确这个问题,下面的两个命令都不要使用Cython:

    # DO NOT use these commands. I repeat: DO NOT use these commands.
    $ pip-2.7 install lxml
    $ easy_install-2.7 install lxml
    

    所以,当我使用Python2时,你只有一个选择,据我所知,这是:从源代码编译,Luke!

    # install build environment and dependencies
    $ kernel_release=$( uname -r )
    $ sudo apt-get install linux-headers-${kernel_release} build-essential -y
    $ sudo apt-get install libxml2-dev libxslt1-dev -y
    
    # Download from github and compile from sources
    $ git clone --branch lxml-3.2.4 https://github.com/lxml/lxml
    $ python2.7 setup.py clean build --with-cython install
    
  • 3

    对于ubuntu 12.04和虚拟环境:

    sudo apt-get install libxml2-dev libxslt-dev
    workon some-virt-env
    pip install lxml
    
  • 73

    尝试通过设置FLAGS环境变量来禁用C编译器优化

    CFLAGS="-O0"  pip install lxml
    

    这解决了我,而不需要更多的RAM

相关问题