无法在Ubuntu中安装lxml版本3.3.5

1 投票
3 回答
8940 浏览
提问于 2025-04-18 06:01

我在我的应用程序中使用了openpyxl这个Python包。使用的时候,我收到了以下提示信息。

/usr/local/lib/python2.7/dist-packages/openpyxl/init.py:31: 用户警告:安装的lxml版本太旧,无法与openpyxl一起使用

warnings.warn("安装的lxml版本太旧,无法与openpyxl一起使用")

openpyxl需要lxml的版本至少是3.2.5,而我电脑上的版本是3.2.0。当我尝试把lxml升级到最新版本,也就是3.3.5时,却遇到了以下中断信息。

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

----------------------------------------

  Rolling back uninstall of lxml

  Replacing /usr/lib/python2.7/dist-packages/lxml
  Replacing /usr/lib/python2.7/dist-packages/lxml-3.2.0.egg-info
Cleaning up...

  Removing temporary dir /tmp/pip_build_root...
Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ov0PUy-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip_build_root/lxml

我需要帮助来解决这个问题。

附注:我已经在我的电脑上安装了lxml所需的依赖包,包括python-dev、libxml2-dev和libxslt1-dev。

3 个回答

3

在Ubuntu(以及其他基于Debian的系统)上,在你开始编译某个软件之前,确保它所需要的依赖包已经安装好。根据你的例子,运行以下命令:

sudo apt-get build-dep python-lxml

这可能需要安装很多软件包,其中一个就是zlib1g-dev正如之前提到的

7
sudo pip install --upgrade lxml

当然可以!请把你想要翻译的内容发给我,我会帮你用简单易懂的语言解释清楚。

2

我觉得你缺少的是 zlib1g-dev 这个东西。

sudo apt-get install zlib1g-dev

运行上面的命令就能解决这个问题。

撰写回答