python 故障归纳
2021-03-05
-
错误描述:ModuleNotFoundError: No module named '_sqlite3'
# 当前环境 [root@test ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@test ~]# python3 -V Python 3.7.9 # 报错信息 ModuleNotFoundError: No module named '_sqlite3'
-
原因及解决办法:
[root@test ~]# yum -y install sqlite-devel # 重新编译python3。步骤请移目另一篇文章:https://www.cnblogs.com/ccbloom/p/11478056.html
2021-03-08
-
错误描述:Could not import the lzma module
# 当前环境 [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
2021-03-11
-
错误描述:ModuleNotFoundError: No module named '_bz2'
# 当前环境 [root@test ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@test ~]# python3 -V Python 3.7.9 # 报错信息 ModuleNotFoundError: No module named '_bz2'
-
原因及解决办法:
# 下载_bz2.cpython-37m-x86_64-linux-gnu.so文件 ## 地址:https://pan.baidu.com/s/1Bp7cnb7knPL9EGQbznN4lA ## 提取码:qnae # 如果你的python版本是3.6,那就是36m,我的是python3.7,得把文件名改为37m [root@test ~]# mv _bz2.cpython-36m-x86_64-linux-gnu.so _bz2.cpython-37m-x86_64-linux-gnu.so [root@test ~]# chmod +x _bz2.cpython-37m-x86_64-linux-gnu.so [root@test ~]# mv _bz2.cpython-37m-x86_64-linux-gnu.so /usr/local/python3/lib/python3.7/lib-dynload # 如果是3.9,则需要yum安装bzip2-devel,然后重新编译python。
2021-03-15
-
错误描述:升级完pip之后,ModuleNotFoundError: No module named 'pip'
# 当前环境 [root@test ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@test ~]# python3 -V Python 3.7.9 [root@test ~]# pip list ModuleNotFoundError: No module named 'pip'
-
原因及解决办法:可能是因为你没有按照提示命令去升级pip导致的,使用下列命令恢复,然后使用提示的命令去升级就可以了。
[root@test ~]# python -m ensurepip [root@test ~]# python -m pip install --upgrade pip
2021-03-16
-
错误描述:RuntimeError: Decompression 'SNAPPY' not available
# 当前环境 [root@test ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@test ~]# python3 -V Python 3.7.9 # 报错信息 RuntimeError: Decompression 'SNAPPY' not available. Options: ['GZIP', 'UNCOMPRESSED']
-
原因及解决办法:
[root@test ~]# pip3 install -i https://mirrors.aliyun.com/pypi/simple/ python-snappy
2021-04-02
-
错误描述:ModuleNotFoundError: No module named '_tkinter'
# 当前环境 [root@test ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@test ~]# python3 -V Python 3.7.9 # 报错信息 ModuleNotFoundError: No module named '_tkinter'
-
原因及解决办法:
[root@test ~]# yum -y install tk-devel # 重新编译python3。步骤请移目另一篇文章:https://www.cnblogs.com/ccbloom/p/11478056.html
2022-06-29
-
错误描述:
# 当前环境 [root@test ~]# cat /etc/redhat-release CentOS Linux release 7.9.2009 (Core) [root@test ~]# python3 -V Python 3.7.9 # 报错信息 [root@test ~]# pyinstaller test.py OSError: Python library not found: libpython3.7.so.1.0, libpython3.7m.so.1.0, libpython3.7mu.so.1.0, libpython3.7m.so, libpython3.7.so
-
原因及解决办法:
# 加上--enable-shared参数重新编译python3。 ./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl --enable-shared --enable-optimizations # 添加动态库查询路径。 [root@test ~]# echo "/usr/local/python3/lib" >>/etc/ld.so.conf [root@test ~]# dconfig
写作不易,转载请注明出处,谢谢~~