我已经安装在我的主目录。
[spatel@~ dev1]$ /home/spatel/python-2.7.3/bin/python -V
Python 2.7.3
我正在尝试运行一个需要Python2.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上安装它们:
软呢帽:
重新构建python。 您可能会注意到,python在配置/构建时会检查许多库,如果您遗漏了其中的一些库,那么在您的案例中很可能无法获得对bz2这样的lib的支持。
您应该获得预构建的二进制文件来避免这种情况。Ubuntu 12.04包python 2.7.3,你的脚本需要的版本。
在CentOS 7上,安装bzip2 devel:
然后重新编译python。
如果python安装在特定的位置,那么只安装
libbz2-dev
是行不通的。centos有一个解决方案:
Centos 6号
半人马座7
python_install_path
通常是/usr/local/lib/python2.7/
,如果您有自定义的python路径,则需要替换它。相关问题 更多 >
编程相关推荐