Python3安装的坑

安装Python3前的必要准备工作

今天在自己的外网服务器安装Pandas后,尝试导入,报错:

/usr/local/lib/python3.7/site-packages/pandas/io/common.py in <module>
      7 from http.client import HTTPException  # noqa
      8 from io import BytesIO
----> 9 import lzma
     10 import mmap
     11 import os

/usr/local/lib/python3.7/lzma.py in <module>
     25 import io
     26 import os
---> 27 from _lzma import *
     28 from _lzma import _encode_filter_properties, _decode_filter_properties
     29 import _compression

ModuleNotFoundError: No module named '_lzma'

解决方法一

https://www.jianshu.com/p/198620bbc5a0

方法二

根本原因在于安装Python3前,系统缺少必要的环境

# 解决 _lzma 缺失提醒
yum install xz-devel

现摘抄https://segmentfault.com/a/1190000017313144如下:

# wget 用于下载源码包
# gcc 和 make 用于编译
yum install wget gcc make

#make报错,Python 有个很重要的内建模块 zipimport 用于从 Zip 压缩包中导入模块
#zipimport.ZipImportError: can't decompress data; zlib not available
yum install zlib-devel

#make install报错,
#ModuleNotFoundError: No module named ‘_ctypes’
yum install libffi-devel

# 解决 import ssl 报错 No module named '_ssl'
yum install openssl-devel

# 解决 import bz2 报错
yum install  bzip2-devel

# 解决 import curses 报错
yum install  ncurses-devel

# 解决 import sqlite3 报错
yum install sqlite-devel

# 解决 _dbm _gdbm 缺失提醒
yum install gdbm-devel

# 解决 _lzma 缺失提醒
yum install xz-devel

# 解决 _tkinter 缺失提醒
yum install tk-devel

# 解决 readline 缺失提醒及方向键行为非预期的问题
yum install readline-devel

最后重新编译安装Pytho3