Python自动化运维入门篇(一)Python3的安装
1.首先去python的官网去下载python3的源码包,python的官网为www.python.org,这里我们下载python3.8.1
2.我们这里是基于Linux系统的环境,所有安装python3之前要先安装一些依赖包
yum -y install gcc
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install readline readline-devel
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install libffi libffi-devel
3.安装完依赖包之后,将下载好的pyton3源码包解压到/usr/local/src中,进到目录进行编译安装
tar -xvzf Python-3.8.1.tgz -C /usr/local/src
cd /usr/local/src/Python-3.8.1
./configure --prefix=/usr/python --enable-shared CFLAGS=-fPIC
4.接下来编译源码安装
make
make install
注:安装的目录就在/usr/python
5.安装完之后需要配置一下将python的路径添加到/etc/ld.so.conf配置文件中
echo "/usr/python/lib" >> /etc/ld.so.conf
vi /etc/ld.so.conf.d/python3.conf
/usr/python/lib #添加
6.执行ldconfig
ldconfig #执行完之后运行python3的时候就不会报找不到库文件的错误了
7.因为Linux系统自带python,它的版本是pyton2.7.5(我这里是Redhat7)系统中原来的python在/usr/bin/python,它是一个软链接,我们不需要修改,我们在这基础上新建一个软链接
ln -s /usr/python/bin/python3 /usr/bin/python3
ln -s /usr/python/bin/pip3 /usr/bin/pip3
8.执行python3命令验证
出现python3的版本这样就安装完成了