简介:在一台操作系统为Centos7的云服务器上搭建Python3环境,记录安装过程备用。
更换yum源
更换原因:下载速度太慢,更换成163的镜像。根据自己的系统版本与位数进入对应的路径下载包然后安装。在这里下载对应版本的repo文件,代码中使用的是7的文件。
#备份repo
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#删除yum源
rpm -aq|grep yum|xargs rpm -e --nodeps
#下载所需文件
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-167.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-cron-3.4.3-167.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
rpm -ivh --force --nodeps *.rpm
rpm -qa|grep yum
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
vi /etc/yum.repos.d/CentOS-Base.repo
:.,$s/$releasever/7/g
yum clean all
yum makecache
yum update -y --skip-broken
安装Python3
yum安装好之后,就可以准备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 libffi-devel
#yum install libffi-devel
# 下载安装Python3.7
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz
mkdir -p /usr/local/python3
tar -zxvf Python-3.7.3.tgz
cd Python-3.7.3
./configure --prefix=/usr/local/python3
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
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
python3 -V
pip3 -V
pip freeze >packages.list
pip3 install -r packages.list
# 有的包没有在pip上发布,可能就需要手动安装了
其他
欢迎交流
勿喷
侵删
一些参考网址
一些问题的解决方案