[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) [root@localhost ~]# uname -a Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
官方下载到本地然后上传到服务器或者wget下载
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar -zxvf Python-3.7.0.tgz -C /usr/local/
cd /usr/local/Python-3.7.0 ./configure make && make install
执行完make&&make install之后,如果出现以下这种报错: “ModuleNotFound:No module named ‘_ctypes’”
这里需要执行:
yum install libffi-devel -y 执行完继续 make && make install
Linux下的软链接其实就相当于Windows下的快捷方式
因为服务器默认的 python/pip 版本是 2,所以建立软连接,将其改为安装版本
ln -s /usr/local/Python-3.7.0/bin/python3 /usr/bin/python ln -s /usr/local/Python-3.7.0/bin/pip3 /usr/bin/pip
yum是依赖python2.7的,你把python改成了3.7了,自然不好使了。但是不用担心,python2.7还在你的系统里。只要修改一下yum里的相关依赖即可
[root@localhost ~]# vim /usr/libexec/urlgrabber-ext-down #! /usr/bin/python2.7 # A very simple external downloader # Copyright 2011-2012 Zdenek Pavlas [root@localhost ~]# vim /usr/bin/yum #!/usr/bin/python2.7 import sys try:
[root@localhost ~]# python -V Python 3.7.0 [root@localhost ~]# pip -V pip 21.1.3 from /usr/local/Python-3.7.0/lib/python3.7/site-packages/pip (python 3.7) [root@localhost ~]# python Python 3.7.0 (default, Jul 17 2021, 16:22:45) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>