Centos 7安装Python3 以及常见报错

Centos 7安装Python3 以及常见报错

以root用户运行命令:
# 查看Linux版本
 cat /proc/version
Linux version 3.10.0-1127.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) ) 


# 下载
wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tgz

# 创建一个专门的文件夹存放python3
mkdir /usr/local/python3

# 移动
 mv /usr/bin/Python-3.7.7.tgz /usr/local/python3
 cd /usr/local/python3

# 解压
tar -zxvf Python-3.7.2.tgz 

# 安装依赖
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install libffi libffi-devel


# 前面的是路径,需要根据自己情况,我是在python文件夹下,编译
Python-3.7.7/configure --prefix=/usr/local/python3/ --with-ssl --enable-shared
make && make install
# --prefix指定自定义的安装目录,可以不指定。但是--with-ssl参数一定要添加,如果省略掉这个参数,在以后执行pip来安装第三方库的时候,将会提示ssl证书错误。--enable-shared参数建议指定,这样便于依赖python的其他软件配置

# 为python3和pip3创建软连接,前面的是python的路径
 ln -s /usr/local/python3/bin/python3 /usr/bin/python3
 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3



# 替换pip源
vi ~/.pip/pip.conf

[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com

运行报错:python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory,原因是系统不能到python库中获取文件,只需要想系统声明python库的路径即可:

vi /etc/ld.so.conf.d/python3.conf

/usr/local/python3/lib


# 链接动态库
ldconfig
成功了吧!!
分享到 :

发表评论

登录... 后才能评论