一键脚本
yum groupinstall 'Development Tools' zlib-devel bzip2-devel gcc openssl-devel ncurses-devel readline-devel -y && wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz && tar -zxf Python* && cd Python-3.6.5 && ./configure --prefix=/usr/local/python3 && make && make install && echo 'export PATH=$PATH:/usr/local/python3/bin' >> ~/.bashrc && rm -f /usr/bin/python && ln -s /usr/local/python3/bin/python3.6 /usr/bin/python && ln -s /usr/local/python3/bin/pip3 /usr/bin/pip && mkdir /root/.pip/ && cat >/root/.pip/pip.conf<<EOF [global] index-url =https://pypi.tuna.tsinghua.edu.cn/simple EOF
1、安装开发包和依赖包
yum groupinstall 'Development Tools' -y #安装开发包
yum install zlib-devel bzip2-devel gcc openssl-devel ncurses-devel -y #安装可能依赖的包
yum install readline-devel -y #不安装进入python解释器的时候可能输入字符会乱码
2、下载 Python3.6代码包
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
3 编译
[root@db02 ~]# tar -zxf Python-3.6.5.tgz
[root@db02 ~]# cd Python-3.6.5
[root@db02 Python-3.6.5]#
./configure --prefix=/usr/local/python3
make && make install
4 设置环境变量
echo 'export PATH=$PATH:/usr/local/python3/bin' >> ~/.bashrc 做一些必要配置 rm -f /usr/bin/python #删除老版本的软链接 ln -s /usr/local/python3/bin/python3.6 /usr/bin/python #做新版本的软链接 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip #pip软链接 mkdir /root/.pip/ #国内镜像 vi /root/.pip/pip.conf cat >/root/.pip/pip.conf<<EOF [global] index-url =https://pypi.tuna.tsinghua.edu.cn/simple EOF
安装mycli
pip install mycli ln -s /usr/local/python3/bin/mycli /usr/bin/mycli
5、更新python2.6的yum配置。
vim /usr/bin/yum
通过vim修改yum的配置
#!/usr/bin/python改为#!/usr/bin/python2.6,保存退出。
完成了python3的安装。