问题描述: 系统为:CentOS Linux release 8.2.2004 (Core)
执行Python脚本的时候出现:
UserWarning: Could not import the lzma module. Your installed Python is incomplete
python3安装pandas库出现: Could not import the lzma module
刚开始的时候浪费了很长时间,有的网上大哥出招说:进入/usr/local/python3/lib/python3.7
目录下,
编辑lzma.py
巴拉巴拉什么的,根本都不管用,依然报错,而且这样的文章抄来抄去不在少数,都不解决问题。
原因分析: 出现该错误的原因,是因为在依次执行完./configure
和 sudo make
的时候出现了错误提示,被忽略了。
如果发现在执行make的时候出现类似下面的错误提示,那么就是因为依赖包没有提前安装好,需要提前安装好。
提示如下:
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_dbm _gdbm _lzma nis
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

解决办法: 依次执行如下命令:
sudo yum install -y xz-devel
cd Python-3.8.5
sudo ./configure --prefix=/usr/local/python3.8.5 --enable-optimizations --with-ssl
sudo make
sudo make install
再次运行python脚本,问题得到解决。
如果是乌班图系统,比如 `Ubuntu 18.04`:
sudo apt-get install lzma
依次执行如下命令:
sudo apt-get install liblzma-dev
sudo apt-get install lzma
sudo ./configure --prefix=/usr/local/python3.8.5 --enable-optimizations --with-ssl
sudo make
sudo make altinstall
补充几个模块依赖包的对应关系:
_lzma
的依赖包是:xz-devel
_dbm
,_gdbm
的依赖包是:gdbm-devel
_sqlite3
的依赖包是:sqlite-devel
readline
的依赖包是:readline-devel
nis
的依赖包是:nispor-devel
注:本文原创由 bluetata
发布于https://bluetata.blog.csdn.net/、转载请务必注明出处。