Linux 环境安装Python3

发布于:2023-01-24 ⋅ 阅读:(15) ⋅ 点赞:(0) ⋅ 评论:(0)

一、安装依赖环境

输入命令: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

二、下载Python3

1.进入opt文件目录下,cd opt/

2.下载python3   (安装自己需要的版本)

输入命令:wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz 

(PS:由于直接下载速度很慢,我这里是直接在官网下载的安装包,然后上传到服务器的)

3.安装Python3

(1)创建目录:  mkdir -p /usr/local/python3

(2)解压下载好的Python-3.x.x.tgz包:  tar -zxvf Python-3.7.1.tgz 

4.进入解压后的目录,编译安装。(编译安装前需要安装编译器yum install gcc)

(1)安装gcc    

输入命令 yum install gcc,确认下载安装输入“y”

(2)3.7版本之后需要一个新的包libffi-devel

安装即可:yum install libffi-devel -y

 

(3)进入python文件夹,生成编译脚本(指定安装目录):

 cd Python-3.7.1

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

#/usr/local/python3为上面步骤创建的目录

 

(4)编译:make

 

(5)编译成功后,编译安装:make install

 

(6)检查python3.7的编译器:/usr/local/python3/bin/python3.7

 

5.建立Python3和pip3的软链:

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

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

 

6.并将/usr/local/python3/bin加入PATH

(1) vim ~/.bash_profile

(2)按“i”,然后贴上下面内容:

# 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

 

(3)按ESC,输入:wq回车退出。

(4)修改完记得执行行下面的命令,让上一步的修改生效:  source ~/.bash_profile

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

python3 -V

pip3 -V

 


网站公告

欢迎关注微信公众号

今日签到

点亮在社区的每一天
签到