# Python标准二进制源码编译安装 # yum安装编译依赖软件包 [root@db01 ~]# yum -y install libffi-devel zlib zlib-devel bzip2 bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel xz-devel gcc gcc-c++ make # 下载Python二进制源码包 [root@db01 ~]# wget -c https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tgz -P /disk # 解压并开始编译 [root@db01 ~]# tar -xf /disk/Python-3.7.7.tgz -C /disk/ [root@db01 ~]# cd /disk/Python-3.7.7/ [root@db01 /disk/Python-3.7.7]# mkdir -p /opt/Python-3.7.7 [root@db01 /disk/Python-3.7.7]# ./configure --prefix=/opt/Python-3.7.7 --enable-optimizations [root@db01 /disk/Python-3.7.7]# make [root@db01 /disk/Python-3.7.7]# make install # 配置环境变量 ln -s /opt/Python-3.7.7 /usr/local/python3 mv /usr/bin/python /usr/bin/python.bak ln -s /usr/local/python3/bin/python3 /usr/bin/python mv /usr/bin/pip /usr/bin/pip.bak ln -s /usr/local/python3/bin/pip3 /usr/bin/pip mv /usr/local/bin/pip /usr/local/bin/pip.bak ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip # 修改yum工具的py解释器版本 ==>> 改为python2 [root@db01 ~]# vim /usr/bin/yum #!/usr/bin/python2 [root@db01 ~]# vim /etc/profile # Python3 export PATH=/usr/local/python3/bin:$PATH # python 查看安装路径 默认 = /usr/local/lib/python3.7 [root@db01 ~]# python Python 3.7.7 (default, May 28 2020, 16:58:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> print(sys.path) # 将pip升级到最新版本 python -m pip install --upgrade pip # 以后需要使用的第三方模块 pip install mysql-connector-python pip install PyMySQL pip install myloginpath pip install redis pip install pymongo pip install paramiko pip install configparser pip install optparse pip install argparse pip install requests pip install xlrd