首页 > 编程语言 > 详细

python3 导入pandas模块提示“Could not import the lzma module”

时间:2021-03-11 17:47:05      阅读:292      评论:0      收藏:0      [点我收藏+]

错误信息

  1. 当前环境
[root@test ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@test ~]# python3 -V
Python 3.7.9
  1. 进入python3交互式环境。
[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)

?

解决办法

  1. 安装依赖包。
[root@test ~]# yum -y install xz-devel python-backports-lzma
[root@test ~]# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple backports.lzma
  1. 编辑lzma.py文件。
[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
  1. 恢复正常
[root@test ~]# python3
>>> import pandas

?
?

写作不易,转载请注明出处,谢谢~~

?

python3 导入pandas模块提示“Could not import the lzma module”

原文:https://www.cnblogs.com/ccbloom/p/14517109.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!