Python

Linux环境安装Python3

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

1、下载程序包

2、安装部署

2.1:上传软件包

  • 将软件包上传至服务器或者直接wget下载
[[email protected] ~]# wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
  • 安装依赖包
[[email protected] ~]# 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.2:创建安装目录

[[email protected] ~]# mkdir /usr/local/python3

2.3:解压程序包

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

2.4:编译安装

[[email protected] ~]# cd Python-3.7.4
[[email protected] Python-3.7.4]# ./configure --prefix=/usr/local/python3 --with-ssl --enable-shared CFLAGS=-fPIC
// --with-ssl添加ssl模块
[[email protected] Python-3.7.4]# make && make install
  • 安装完成没有提示错误便安装成功了
Linux环境安装Python3-浅时光博客
来源(Source):https://www.dqzboy.com

3、建立软连接

[[email protected] ~]# ln -sv /usr/local/python3/bin/python3.7 /usr/bin/python3
[[email protected] ~]# ln -sv /usr/local/python3/bin/pip3.7 /usr/bin/pip3

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

[[email protected] ~]# 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()

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

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

5、关于yum无法使用问题来源(Source):https://www.dqzboy.com

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

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

7.1:方案1

[[email protected] ~]# cp /usr/local/python3/lib/libpython3.7m.so.1.0 /usr/lib64

7.1:方案2

[[email protected] ~]# 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存放目录
[[email protected] ~]# find / -name libpython3.7m.so.1.0
/usr/local/python3/lib/libpython3.7m.so.1.0

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

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