CentOS系统 python3+python2 & Ipython安装
https://www.cnblogs.com/albertrui/p/8093384.html
一、安装依赖环境
输入命令:
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
yum -y install openssl
yum -y install openssl-devel yum -y install gcc yum -y install libffi-devel (3.7版本之后需要一个新的包libffi-devel)
二、下载Python3
1.下载python3
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
2. 解压tag包
tar -xf Python-3.9.1.tgz
三.安装Python3
安装在/usr/local/python3(具体安装位置看个人喜好)
(1)创建安装目录:
mkdir -p /usr/local/python3
(2)切换到目录内,开始配置编译参数
cd Python-3.9.1 ./configure --prefix=/usr/local/python3 #/usr/local/python3为上面步骤创建的目录
(3)编译:make
make
(4)编译成功后,编译安装:make install
make install
三、配置环境变量,python3和pip3软连接
1. 将python2 的连接删除
mv /usr/bin/python{,2.bak}
mv /usr/bin/pip{,2.bak}
2.创建python3软连接
ln -s /usr/local/python3/bin/pi /usr/bin/python ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
3.修改yum所用pyton路径为python2.7
因为yum使用python2,因此替换为python3后可能无法正常工作,继续使用这个python2.7.5
因此修改yum配置文件
/usr/bin/yum
/usr/libexec/urlgrabber-ext-down
把文件头部的#!/usr/bin/python改成#!/usr/bin/python2保存退出即可。
4.将/usr/local/python3/bin加入PATH
# .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
5. 刷新当前环境变量
source ~/.bash_profile
posted on 2019-09-21 10:38 zhangmingda 阅读(324) 评论(0) 编辑 收藏 举报