[root@test ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@test ~]# python3 -V
Python 3.7.9
[root@test ~]# python3
>>> import pandas
/usr/local/python3/lib/python3.7/site-packages/pandas/compat/__init__.py:97: UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
warnings.warn(msg)
?
[root@test ~]# yum -y install xz-devel python-backports-lzma
[root@test ~]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple backports.lzma
[root@test ~]# cp /usr/local/python3/lib/python3.7/lzma.py{,.bak}
[root@test ~]# vim /usr/local/python3/lib/python3.7/lzma.py
# 找打如下两行
from _lzma import *
from _lzma import _encode_filter_properties, _decode_filter_properties
# 更换为如下
try:
from _lzma import *
from _lzma import _encode_filter_properties, _decode_filter_properties
except ImportError:
from backports.lzma import *
from backports.lzma import _encode_filter_properties, _decode_filter_properties
[root@test ~]# python3
>>> import pandas
?
?
写作不易,转载请注明出处,谢谢~~
?
python3 导入pandas模块提示“Could not import the lzma module”
原文:https://www.cnblogs.com/ccbloom/p/14517109.html