python安装

傻男人 1年前 ⋅ 633 阅读

python安装

一、python3安装

1)、安装python3的依赖

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

A、进入opt文件目录下

cd opt/

B、下载python3(可以到官方先看最新版本多少)

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

如果出现 找不到wget命令,安装其依赖

yum -y install wget

D、安装Python3

安装在/usr/local/python3(具体安装位置看个人喜好)

a、创建目录

mkdir -p /usr/local/python3

b、解压下载好的Python-3.7.1的压缩包

tar -zxvf Python-3.7.1.tgz

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

a、安装gcc

yum install gcc

b、3.7版本之后需要一个新的包libffi-devel

yum install libffi-devel

c、进入python文件夹,生成编译脚本(指定安装目录)
cd Python-3.7.1
./configure --prefix=/usr/local/python3  

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

d、编译:

make

e、编译成功后,编译安装:

make install

f、检查python3.7的编译器

/usr/local/python3/bin/python3.7

F、建立Python3和pip3的软链

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

G、并将/usr/local/python3/bin加入PATH

vim /etc/profile

将以下的内容写入文件中

# 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

H、检查Python3及pip3是否正常可用:

python3 -V
pip3 -V

全部评论: 0

    我有话说: