升级python2.7.5到2.7.18,并替换虚拟环境python版本

升级python2.7.5到2.7.18,并替换虚拟环境python版本

    • 获取安装包
    • 安装相关依赖环境
    • 编译安装python2.7.18
    • 创建新python版本软连接
    • 备份原虚拟环境
    • 创建新的虚拟环境
    • 备份文件,补充相应的安装包
      • 补充服务文件
    • 对于可能会出现的cffi的错误解决办法:

查考:https://blog.csdn.net/weixin_43822878/article/details/106957248

获取安装包

wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar -xvzf Python-2.7.18.tgz

安装相关依赖环境

#执行命令前可能需要更换yum源
yum install gcc openssl openssl-devel ncurses-devel.x86_64 bzip2-devel sqlite-devel python-devel zlib  -y
yum install gdbm-devel

编译安装python2.7.18

mkdir /usr/local/python-2.7.18
cd Python-2.7.18
./configure --prefix=/usr/local/python-2.7.18
make
make install

创建新python版本软连接

rm  -f  /usr/bin/python
ln -s /usr/local/python-2.7.18/bin/python2.7  /usr/bin/python

将下列两个文件首行的 #!/usr/bin/python 都改为 #!/usr/bin/python2,防止yum命令问题
vim /usr/bin/yum
vim /usr/libexec/urlgrabber-ext-down

备份原虚拟环境

mkdir  /usr/local/bare-agent-bak
cp -r /usr/local/bare-agent  /usr/local/bare-agent-bak   && rm -rf /usr/local/bare-agent/*

创建新的虚拟环境

virtualenv -p   /usr/bin/python   /usr/local/bare-agent/

备份文件,补充相应的安装包

mv  /usr/local/bare-agent/lib/python2.7/site-packages  /usr/local/bare-agent/lib/python2.7/site-packages-bak
cp -r /usr/local/bare-agent-bak/bare-agent/lib/python2.7/site-packages  /usr/local/bare-agent/lib/python2.7/

补充服务文件

cp -r /usr/local/bare-agent-bak/bare-agent/etc  /usr/local/bare-agent/
cp /usr/local/bare-agent-bak/bare-agent/bin/bare-agent  /usr/local/bare-agent/bin/

对于可能会出现的cffi的错误解决办法:

卸载未识别到的pip包,在虚拟环境目录重新安装对应pip包

/usr/local/bare-agent/bin/pip uninstall cffi
yum install libffi-devel -y
/usr/local/bare-agent/bin/pip install  cffi-1.10.0.tar.gz

#重启服务,查看服务状态
systemctl restart 服务
systemctl status 服务
#验证服务状态
curl 127.0.0.1:

你可能感兴趣的:(python,linux)