PS:如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,
比如yum!!!!!
不要动现有的python2环境!
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
2.下载Python3.4
# wget https://www.python.org/ftp/python/3.4.10/Python-3.4.10.tgz
3.安装Python3.4
我安装到了 /usr/local/python3 (具体看你)
创建目录
# mkdir -p /usr/local/python3
4.解压下载好的Python-3.4.10.tgz包
# tar -xvf Python-3.4.10.tgz
5. 进入解压后的目录,编译安装。
# cd Python-3.4.10/ # ./configure --prefix=/usr/local/python3
make
# make
make install
# make install
6.建立python3的软链
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
7.并将/usr/local/python3/bin加入PATH
# vim ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin:/usr/local/python3/bin export PATH
按ESC,输入:wq回车退出。
修改完记得执行行下面的命令,让上一步的修改生效:
# source ~/.bash_profile
检查Python3及pip3是否正常可用:
# python3 -V