Python

Linux环境安装Python3

浅时光 · 2月2日 · 2020年 19678次已读

1、下载程序包

2、安装部署

2.1:上传软件包

  • 将软件包上传至服务器或者直接wget下载
[localhost@root ~]# wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
  • 安装依赖包
[localhost@root ~]# yum -y install zlib zlib-devel bzip2 bzip2-devel ncurses ncurses-devel readline readline-devel openssl openssl-devel openssl-static xz lzma xz-devel sqlite sqlite-devel gdbm gdbm-devel tk tk-devel libffi libffi-devel gcc make glibc-kernheaders

2.文章来源(Source):浅时光博客2:创建安装目录文章来源(Source):https://www.dqzboy.com

[localhost@root ~]# mkdir /usr/local/python3

2.3:解压程序包

  • 解压至当前所在目录即可
[localhost@root ~]# tar -zxvf Python-3.7.4.tgz

2.4:编译安装

[localhost@root ~]# cd Python-3.7.4
[localhost@root Python-3.7.4]# ./configure --prefix=/usr/local/python3 --with-ssl --enable-shared CFLAGS=-fPIC
// --with-ssl添加ssl模块
[localhost@root Python-3.7.4]# make && make install
  • 安装完成没有提示错误便安装成功了
Linux环境安装Python3-浅时光博客

3、建立软连接

[root@localhost ~]# ln -sv /usr/local/python3/bin/python3.7 /usr/bin/python3
[root@localhost ~]# ln -sv /usr/local/python3/bin/pip3.7 /usr/bin/pip3

4、测试一下python3是否可以用

[root@localhost ~]# python3
Python 3.7.0 (default, Jul 28 2018, 22:47:29) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello world!")
hello world!
>>> exit()

[root@localhost ~]#  pip3 --version
pip 18.1 from /usr/local/python38/lib/python3.7/site-packages/pip (python 3.7)

#升级pip3的版本
[root@localhost ~]# pip3 install --upgrade pip
[root@localhost ~]# pip3 --version
pip 20.1.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
  • 到此python3安装完成

5、关于yum无法使用问题

  • 如果是直接替换掉了默认的系统自带的python,那么需要更改以下配置;
    yum包管理是使用python2.x写的,将python2.x升文章来源(Source):浅时光博客级到python3.7以后,由于python版本语法兼容性导致问题出现
  • 解决方案如下
[root@localhost ~]# vim /usr/bin/yum
Linux环境安装Python3-浅时光博客
[root@localhost ~]# vim /usr/libexec/urlgrabber-ext-down
Linux环境安装Python3-浅时光博客

7、找不到libpython3.7m.so.1.0

7.1:方案1

[root@localhost ~]# cp /usr/local/python3/lib/libpython3.7m.so.1.0 /usr/lib64

7.1:方案2

[root@localhost ~]# pip3 install Pillow
/usr/local/python3/bin/python3.7: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

//找到libpython3.7m.so.1.0存放目录
[root@localhost ~]# find / -name libpython3.7m.so.1.0
/usr/local/python3/lib/libpython3.7m.so.1.0

//将libpython3.7m.so.1.0所在目录输入到python3.7.conf
[root@localhost ~]# echo "/usr/local/python3/lib " > /etc/ld.so.conf.d/python3.7.conf

[root@localhost ~]# ldconfig
[root@localhost ~]# ldd /usr/local/python3/bin/python3.7
Linux环境安装Python3-浅时光博客
Linux环境安装Python3-浅时光博客
0 条回应
    本站已安全运行: | 耗时 0.223 秒 | 查询 125 次 | 内存 17.40 MB