Linux 安装 Python3.7
1.安装依赖包
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel gcc
2.下载Python3.7源码
1) 下载 # wget http://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz 2)解压 # tar -xvf Python-3.7.1.tar.xz && cd Python-3.7.1/
3.执行配置文件,编译,编译安装
# ./configure --prefix=/usr/local/python37 # make && make install
安装完成没有提示错误便安装成功了
4.建立软连接
# mv /usr/bin/python /usr/bin/python_bak # ln -s /usr/local/python37/bin/python3.7 /usr/bin/python # ln -s /usr/local/python37/bin/pip3.7 /usr/bin/pip
5.测试Python是否可用
# python Python 3.7.1 (default, Jan 14 2019, 10:30:01) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> print("hello world!") hello world! >>> exit() # pip --version pip 10.0.1 from /usr/local/python37/lib/python3.7/site-packages/pip (python 3.7)
注:
安装完之后可能导致yum不能用,报错为:
# yum -y install redis File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax
解决办法:
# vi /usr/bin/yum 和 /usr/libexec/urlgrabber-ext-down
将第一行"#!/usr/bin/python" 改为 "#!/usr/bin/python2.7"即可。
参考博客:https://www.cnblogs.com/yhongji/p/9383857.html
非常感谢