centos ModuleNotFoundError: No module named bz2

centos ModuleNotFoundError: No module named bz2

在操作系统中安装zlib和bz2相关库

yum install zlib zlib-devel

yum -y install bzip2 bzip2-devel ncurses openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi-devel

下载bzip2

https://sourceforge.net/projects/bzip2/

tar -zxf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
这一步比较重要,使bzip2 根据另一个Makefile来编译,就是Makefile-libbz2_so文件,创建一个动态的libbz.so库文件,然后把bzip2工具连接到这个库上

注:装python的时候如果没有这一步,python安装不上bz2模块

make -f Makefile-libbz2_so
make && make install

卸载:如果要重新安装bzip2,要先执行:rm -vf /usr/bin/bz* 命令,不然make install 命令会失败。

重新编译python

export CFLAGS="-I/usr/include"
export LDFLAGS="-L/usr/lib64"
export LD_LIBRARY_PATH=/usr/lib64
 
make distclean
./configure --prefix=/usr/local/python3 --enable-optimizations  
make && make install

python
import bz2

你可能感兴趣的:(centos ModuleNotFoundError: No module named bz2)