缺少python bz2模块

我已安装在主目录中。

[spatel@~ dev1]$ /home/spatel/python-2.7.3/bin/python -V

Python 2.7.3

我正在尝试运行一个需要python 2.7.x版本的脚本,而我却丢失了bz2错误

[spatel@~ dev1]$ ./import_logs.py

Traceback (most recent call last):

File "./import_logs.py", line 13, in <module>

import bz2

ImportError: No module named bz2

我尝试安装bz2模块,但出现很多错误

 [spatel@dev1 python-bz2-1.1]$ /home/spatel/python-2.7.3/bin/python setup.py install

...

...

...

bz2.c:1765: error: âBZ_FINISH_OKâ undeclared (first use in this function)

bz2.c:1765: warning: comparison between pointer and integer

bz2.c:1771: error: âPyMemberDefâ has no member named âavail_outâ

bz2.c:1778: error: âPyMemberDefâ has no member named ânext_outâ

bz2.c:1778: error: âPyMemberDefâ has no member named âtotal_out_hi32â

bz2.c:1778: error: âPyMemberDefâ has no member named âtotal_out_lo32â

bz2.c:1778: error: invalid operands to binary +

bz2.c:1778: warning: statement with no effect

bz2.c:1779: error: âPyMemberDefâ has no member named âavail_outâ

bz2.c:1779: error: âPyMemberDefâ has no member named ânext_outâ

bz2.c:1779: error: invalid operands to binary -

bz2.c:1779: error: invalid operands to binary -

bz2.c:1779: warning: statement with no effect

bz2.c:1783: error: âPyMemberDefâ has no member named âavail_outâ

bz2.c:1784: error: âPyMemberDefâ has no member named âtotal_out_hi32â

bz2.c:1784: error: âPyMemberDefâ has no member named âtotal_out_lo32â

bz2.c:1784: warning: passing argument 2 of â_PyString_Resizeâ makes integer from pointer without a cast

error: command 'gcc' failed with exit status 1

回答:

可能是从源代码构建python时,没有bz2标头。

在Ubuntu / Debian上安装它们:

sudo apt-get install libbz2-dev

软呢帽:

sudo yum install bzip2-devel

并再次构建python。您可能会注意到python在配置/构建时会检查很多库,如果您错过其中的一些库,那么您的案例可能就不会支持bz2之类的库。

您应该获取预构建二进制文件,以避免此类情况。Ubuntu 12.04包含python

2.7.3,这是脚本所需的版本。

以上是 缺少python bz2模块 的全部内容, 来源链接: utcz.com/qa/428117.html

回到顶部