Python3安装报错
LiuSw Lv6

Python3安装报错

报错1

(1).报错内容

1
2
3
4
5
6
7
8
[root@localhost ~]# python3
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec prefix>
Consider setting SPYTHONHOME to <prefix>[:<exec prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encodin
ModuleNotFoundiA-ror: No module named 'encodings'
Current thread 0x80007/218eec9740 (most recent call first):
Aborted

(2).报错原因

同一服务器安装了多版本的python版本

1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# ll /usr/bin/python*
lrwxrwxrwx. 1 root root 7 11月 27 16:41 /usr/bin/python -> python2
lrwxrwxrwx. 1 root root 9 11月 27 16:41 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 10月 31 2018 /usr/bin/python2.7
lrwxrwxrwx. 1 root root 9 1月 24 17:19 /usr/bin/python3 -> python3.6
-rwxr-xr-x. 1 root root 12711504 1月 24 09:38 /usr/bin/python3.6
lrwxrwxrwx. 1 root root 17 1月 24 17:19 /usr/bin/python3.6-config -> python3.6m-config
-rwxr-xr-x. 1 root root 12711504 1月 24 09:38 /usr/bin/python3.6m
-rwxr-xr-x. 1 root root 3105 1月 24 09:38 /usr/bin/python3.6m-config
lrwxrwxrwx. 1 root root 16 1月 24 17:19 /usr/bin/python3-config -> python3.6-config

(3).解决方案

添加环境变量:

1
2
3
4
5
6
vi /etc/profile

# 最后一行添加(注意安装路径,可能在其他路径,不知道可以用find / -name python3.6查找)
export PYTHONPATH=/usr/lib/python3.6
export PYTHONHOME=/usr/bin/python3.6
export PYTHONHOME=$PYTHONHOME:/usr/lib/python3.6/site-packages

加载环境变量

1
source etc/profile

执行python3命令

1
2
3
4
5
[root@localhost ~]# python3
Python 3.6.8 (default, Jan 21 2022, 15:07:01)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

报错2

(1).报错内容

1
2
3
在CentOS7上安装完Python3后,运行python3时提示libpython3.7m.so.1.0不存在。我们可以看到以下错误信息
[root@carbon ~]# python3
python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

(2).报错原因

1
由于安装完Python3后,没有将libpython3.7m.so.1.0放入/usr/lib64中,导致初始化时无法加载该文件。解决方法也非常简单,我们只需要把文件复制到/usr/lib64目录下。需要注意的是本文的系统是64位的操作系统,并且安装的python也是64位的。

(3).解决方案

复制libpython3.7m.so.1.0文件到/usr/lib64下

1
cp /usr/local/src/Python-3.7.4/libpython3.7m.so.1.0 /usr/lib64
 评论