编译安装python3.6.1

如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境,比如yum

 

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

wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

mkdir -p /usr/local/python3    #目录自行指定

tar xvf Python-3.6.1.tgz

cd Python-3.6.1/

./configure --prefix=/usr/local/python3 

make

make install

 

3.建立python3的软连接

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

 

4.将/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
 
source ~/.bash_profile  #使文件生效
 
 

5.检查Python3及pip3是否正常可用

# python3 -V
Python 3.6.1
# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
 
 

6.不行的话在创建一下pip3的软链接

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
 
 
参考博客:https://www.cnblogs.com/kimyeee/p/7250560.html
posted @ 2020-12-22 15:36  公博义  阅读(12)  评论(0编辑  收藏  举报