详解Python 2.6 升级至 Python 2.7 的实践心得
作者:王奥OX 时间:2022-01-03 09:47:09
前言
CentOS 6.8 安装 Python 2.7.13,因为软件版本上的需求所以考虑将 Python 升级至 2.7.13,加上生产环境还是以 RHEL 6 为主,互联网自动化运维平台大多数也推荐以Python 2.7.x + CentOS 6.x 来操作,选择 Python 2 还是 Python 3 也没有定论,找到适合的搭配即可。
简单安装
因为Python 2.7.13以后版本会自动完善yum配置,所以不必参考以前的网上文章去修改其他地方
# 查看当前系统中的 Python 版本,返回 Python 2.6.6 为正常
python --version
Python 2.6.6
# 检查 CentOS 版本,返回 CentOS release 6.8 (Final) 为正常
cat /etc/redhat-release
CentOS release 6.8 (Final)
# 安装所有的开发工具包
yum groupinstall -y "Development tools"
# 安装其它的必需包
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
# 下载、编译和安装 Python 2.7.13
#wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar zxf Python-2.7.13.tgz
cd Python-2.7.13
./configure
make && make install
# 查看新的 Python 版本,返回 Python 2.7.13 为正常
python --version
Python 2.7.13
ansible离线安装实践
这里利用了一些内网离线安装ansible的小技巧。
# Install Python
tar xf Python-2.7.13.tgz
cd Python-2.7.13
./configure
make
make install
# ImportError: No module named six.moves
tar xf six-1.10.0.tar.gz
cd six-1.10.0
python setup.py install
cd ..
# ImportError: No module named packaging.version
tar xf packaging-16.8.tar.gz
cd packaging-16.8
python setup.py install
cd ..
# ImportError: No module named pyparsing
tar xf pyparsing-2.2.0.tar.gz
cd pyparsing-2.2.0
python setup.py install
cd ..
# ImportError: No module named appdirs
tar xf appdirs-1.4.3.tar.gz
cd appdirs-1.4.3
python setup.py install
cd ..
# Install Setuptools
unzip setuptools-34.2.0.zip
cd setuptools-34.2.0
python setup.py install
cd ..
# Install pip
tar xf pip-9.0.1.tar.gz
cd pip-9.0.1
python setup.py install
cd ..
# pip 离线下载依赖包
pip install -d ~/tmp/ ansible
pip install -d ~/tmp/ ansible-cmdb
# pip 离线安装
pip install ansible --index-url=http://172.31.197.1:7000/simple/ --trusted-host=172.31.197.1
pip install ansible-cmdb --index-url=http://172.31.197.1:7000/simple/ --trusted-host=172.31.197.1
# 查看安装好的版本
[root@ansible-wangao ansible]# pip -V
pip 9.0.1 from /usr/local/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg (python 2.7)
[root@ansible-wangao ansible]# ansible --version
ansible 2.3.0.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.13 (default, Apr 25 2017, 17:19:23) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
[root@ansible-wangao ansible]# ansible-cmdb --version
ansible-cmdb v1.20
# 更换豆瓣pip源
vim $HOME/.pip/pip.conf
[global]
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
Windows 安装 Python 2.7.x
下载Python,如 2.7.13
https://www.python.org/downlo...
https://www.python.org/ftp/py...
安装时注意勾选环境变量Add python.exe to Path
安装python2.7.13默认自带pip版本为9.0.1
PS C:UsersAdministrator> pip -V
pip 9.0.1 from c:python27libsite-packages (python 2.7)
安装Python后升级pippython -m pip install --upgrade pip
# 更换pypi国内源,运行以下python代码会自动建立pip.ini
import os
ini="""[global]
index-url = https://pypi.doubanio.com/simple/
[install]
trusted-host=pypi.doubanio.com
"""
pippath=os.environ["USERPROFILE"]+"\\pip\\"
if not os.path.exists(pippath):
os.mkdir(pippath)
with open(pippath+"pip.ini","w+") as f:
f.write(ini)
来源:https://segmentfault.com/a/1190000009213601
标签:python2.6,升级
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python使用numpy模块实现矩阵和列表的连接操作方法
2023-02-17 21:05:41
python实现最小二乘法线性拟合
2022-04-01 03:46:49
![](https://img.aspxhome.com/file/2023/6/95266_0s.jpg)
python实现从pdf文件中提取文本,并自动翻译的方法
2021-06-08 18:55:56
![](https://img.aspxhome.com/file/2023/5/84135_0s.jpg)
CSS雪碧:要还是不要?
2009-11-16 13:01:00
php文件下载后无法打开的处理方案及代码
2023-06-13 19:12:03
Python3安装模块报错Microsoft Visual C++ 14.0 is required的解决方法
2021-02-14 00:18:22
![](https://img.aspxhome.com/file/2023/3/76023_0s.png)
asp 数组 重复删除函数代码
2011-03-03 10:47:00
在Django的模型中添加自定义方法的示例
2021-12-07 17:14:58
Python3中bytes类型转换为str类型
2022-05-19 16:47:31
![](https://img.aspxhome.com/file/2023/6/111936_0s.png)
利用Python实现学生信息管理系统的完整实例
2022-03-12 10:35:03
![](https://img.aspxhome.com/file/2023/9/79619_0s.png)
asp代码WinHttp.WinHttpRequest.5.1使用例子
2010-03-11 21:28:00
浅谈Python响应式类库RxPy
2021-12-24 12:44:26
![](https://img.aspxhome.com/file/2023/3/78453_0s.png)
Python 中类的构造方法 __New__的妙用
2021-04-06 04:45:56
如何将服务器上的python代码通过QQ发送回传信息(附实现方法)
2022-04-24 04:27:08
![](https://img.aspxhome.com/file/2023/8/109518_0s.jpg)
Python深度强化学习之DQN算法原理详解
2023-03-05 12:02:51
![](https://img.aspxhome.com/file/2023/9/83889_0s.gif)
python django 原生sql 获取数据的例子
2023-02-16 18:35:02
PHP设计模式之迭代器模式浅析
2023-05-25 11:26:26
python和java哪个学起来更简单
2023-06-11 22:49:59
Python定时发送消息的脚本:每天跟你女朋友说晚安
2023-05-26 02:47:14
![](https://img.aspxhome.com/file/2023/3/63883_0s.png)
交互设计实用指南系列(9)—一次点击
2010-02-08 12:42:00
![](https://img.aspxhome.com/file/UploadPic/20102/8/guanji-80s.jpg)