环境:centos7.6

python3版本:3.6.8
pip3版本:18.1
1、下载 python3.6.8 包
wget https://www.python.org/ftp/python/3.6.8/Python-3.6.8.tgz
2、解压
tar -zxvf Python-3.6.8.tgz
3、编译
cd Python-3.6.8
./configure
注:将python的环境编译到/usr/bin/python3的目录下,和python2一个目录下;如需编译到指定自定义目录,可添加 –prefix=/usr/local/python3指定
4、安装
make
make install
5、创建软连接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
6、测试
python3 -V
pip3 -V
备注
-
1:python3安装完以后,pip3默认安装;如需单独安装pip3,见pip3安装和卸载以及常用命令
-
2:依照上面的方法安装完python3以后,系统中python3和python2是并行存在的,执行python时,默认还是python2,想要使用python3,要用python3

如果我们的python脚本是用python3写的,那么脚本中指定执行环境即可,如hello_world.py
# 指定用什么解释器运行脚本以及解释器所在的位置还有文件编码
#!/bin/python3
# -*- coding: UTF-8 -*-
print("hello world")
如果还不行,则执行脚本时,可直接声明是用python3,如
python3 hello_world.py

网友评论