在linux上怎么安装python_在linux上安装python3

我们原装的centos上是有python2.7的,不建议删除,可以做个python3共存的。

输入Python命令,查看可以得知是Python2.7.5版本

# python

Python 2.7.5 (default, Nov 20 2015, 02:00:19)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

>>>

查看原装python路径

# which python

/usr/bin/python

可以查看位置,一般是位于/usr/bin/python目录下。

下面介绍安装Python3的方法

首先安装依赖包,这个比较多,我这里写的的比较全,要是有时候make或者make install 出现问题,大部分都是依赖包缺失或者损坏,需要一次性安好。

# yum -y groupinstall "Development tools"

# 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 gcc gcc-c++ zlib zlib-devel libffi-devel

然后根据自己需求下载不同版本的Python3,我下载的是Python3.7.0的tar包,直接常规操作即可

# wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0b3.tgz

# tar -xvf Python-3.7.0b3.tgz

# cd Python-3.7.0b3/

# ./configure --prefix=/data/soft/python/

# make && make install

创建软连接

# ln -s /data/soft/python/bin/python3 /data/soft/python3

# ln -s /data/soft/python/bin/pip3 /data/soft/pip3

加入path路径

# vim /etc/profile

加入下面两行

PATH=/data/soft/python/bin:/data/soft/python/lib:$PATH

export PATH

执行变量,让设置的路径生效

# source /etc/profile

在命令行中输入python3测试

# python3

Python 3.7.0b3 (default, May 2 2018, 13:55:41)

[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>>

大功告成,写完收工!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值