centos离线安装python3

方法一

首先找到一台有网络的相同环境电脑
如果是centos6,因为国内yum镜像源已经将其迁移到vault需要修改yum源为清华源vault源

修改镜像源

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base  
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-$releasever - Updates 
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras  
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus  
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib  
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

根据系统版本修改$releasever值

yum clean all && yum makecache
yum install yum-plugin-downloadonly -y
yum install  --downloadonly --downloaddir=./pydep/  bzip2-devel gcc gcc-c++ autoconf automake make zlib zlib-devel -y 

以上安装的是centos6.5的依赖具体的依赖需要根据不同的环境添加
下载python
http://npm.taobao.org/mirrors/python/

安装python依赖

rpm -ivh pydep/*
rpm -Uvh pydep/*

安装python

tar -xzvf Python-3.6.0.tgz
cd ./Python-3.6.0
./configure --prefix=/usr/local/python36 
make && make install
ln -s /usr/local/python36/bin/python3.6 /usr/bin/python36

将python3软连接到了python36
后面运行python3用python36这个命令

方法二

直接安装miniConda,无需安装依赖
前往清华下载
https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh

sh Miniconda3-latest-Linux-x86_64.sh 

根据命令提示一步步安装
运行时如果指定了安装路径则需要记下来
默认是/root/miniconda3

添加环境变量

sudo vi /etc/profile

最后一行加上

export PATH=$PATH:/刚刚指定的路径/bin

保存后退出

source /etc/profile
source activate 

然后可以用conda创建虚拟环境愉快的玩耍了

你可能感兴趣的:(centos离线安装python3)