无法在虚拟环境(python)中安装 lxml

无法在虚拟环境(python)中安装 lxml

我无法安装 lxml。系统中我有 python-lxml 包,但我需要其他...请帮忙,如果可以的话 - 我的任务是使用 virtualenv 在虚拟环境中安装 lxml 进行开发。我发现这个解决方案成功修复了 lxml 的安装:

$ sudo apt-get install libxml2 libxml2-dev libxslt-dev build-essential python-dev
$ sudo ldconfig

然后:

$ source bin/activate # for activate enviroment
(env) $ pip install lxml

但我有很多问题。

第一个问题是安装 build-essential 及其依赖项 -为什么 build-essential 失败了?

解决了!谢谢!

接下来我有这个(输出):

(env) $ pip install lxml

...

i686-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -lxslt -lexslt -lxml2 -lz -lm -o build/lib.linux-i686-2.7/lxml/etree.so

/usr/bin/ld: cannot find -lz

collect2: error: ld returned 1 exit status

error: command 'i686-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /tmp/1/bin/python -c "import setuptools, tokenize;__file__='/tmp/1/build/lxml/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-DpYhbY-record/install-record.txt --single-version-externally-managed --compile --install-headers /tmp/1/include/site/python2.7 failed with error code 1 in /tmp/1/build/lxml
Storing debug log for failure in /home/constantia/.pip/pip.log

我读过这个说明http://lxml.de/installation.html然后尝试:

STATIC_DEPS=true pip install lxml

我尝试:

(env) $ STATIC_DEPS=true pip install lxml

...


  File "buildlibxml.py", line 268, in call_subprocess

    raise Exception('Command "%s" returned code %s' % (cmd_desc, returncode))

Exception: Command "make -j3" returned code 512

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/1/build/lxml
Traceback (most recent call last):
  File "/tmp/1/bin/pip", line 11, in <module>
    sys.exit(main())
  File "/tmp/1/local/lib/python2.7/site-packages/pip/__init__.py", line 185, in main
    return command.main(cmd_args)
  File "/tmp/1/local/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main
    text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 13: ordinal not in range(128)

我理解原因可能是 LANG 变量,因此尝试以下操作:

$ unset LANG

我有(输出):

(env) $ STATIC_DEPS=true pip install lxml

...

  File "buildlibxml.py", line 268, in call_subprocess

    raise Exception('Command "%s" returned code %s' % (cmd_desc, returncode))

Exception: Command "make -j3" returned code 512

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/1/build/lxml
Storing debug log for failure in /home/constantia/.pip/pip.log

因此,我尝试使用 easy_install 和 STATIC_DEPS=true

我有(输出):

(env) $ STATIC_DEPS=true pip install lxml

...

make[2]: *** [progname.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory `/tmp/easy_install-bqh5aG/lxml-3.3.5/build/tmp/libiconv-1.14/srclib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/tmp/easy_install-bqh5aG/lxml-3.3.5/build/tmp/libiconv-1.14/srclib'
make: *** [all] Error 2
Traceback (most recent call last):
  File "/tmp/1/bin/easy_install", line 11, in <module>
    sys.exit(main())
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1909, in main
    with_ei_usage(lambda:
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1896, in with_ei_usage
    return f()
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1913, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 358, in run
    self.easy_install(spec, not self.no_deps)
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 593, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 623, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 809, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1015, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1000, in run_setup
    run_setup(setup_script, args)
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 50, in run_setup
    lambda: execfile(
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 100, in run
    return func()
  File "/tmp/1/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 52, in <lambda>
    {'__file__':setup_script, '__name__':'__main__'}
  File "setup.py", line 229, in <module>
  File "setup.py", line 140, in setup_extra_options
  File "/tmp/easy_install-bqh5aG/lxml-3.3.5/setupinfo.py", line 57, in ext_modules
  File "/tmp/easy_install-bqh5aG/lxml-3.3.5/buildlibxml.py", line 348, in build_libxml2xslt
  File "/tmp/easy_install-bqh5aG/lxml-3.3.5/buildlibxml.py", line 285, in cmmi
  File "/tmp/easy_install-bqh5aG/lxml-3.3.5/buildlibxml.py", line 268, in call_subprocess
Exception: Command "make -j3" returned code 512

所以我很伤心,不知道该怎么办。我希望 Stack Exchange 社区能提供帮助。

抱歉,我的问题是关于英语的(这不是我的母语)。

答案1

表示-lz名为 的库文件libz.so。此文件由包提供zlib1g-dev。运行sudo apt-get install zlib1g-dev以安装包,然后重试原始命令(不带STATIC_DEPS)。

相关内容