Python版本升级
CentOS 6.3自带的Python版本为2.6,首先需要升级到2.7版本。由于旧版本的Python已被深度依赖,所以不能卸载原有的Python,只能全新安装。
1.下载Python-2.7.4.tgz
wget http://python.org/ftp/python/2.7.4/Python-2.7.4.tgz
2. 解压安装,命令如下:
1 tar -xvf Python-2.7.4.tgz2 cd Python-2.7.43 ./configure --prefix=/usr/local/python2.74 make5 make install
3. 创建链接来使系统默认python变为python2.7
mv /usr/bin/python /usr/bin/python.oldln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python
4. 查看Python版本
python –V
5. 修改yum配置(否则yum无法正常运行)
vim /usr/bin/yum将第一行的#!/usr/bin/python修改为系统原有的python版本地址#!/usr/bin/python2.6
至此CentOS6.3系统Python已成功升级至2.7.4版本
Linux下python2.7安装pip
首先下载并安装setuptools:
#wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py#python ez_setup.py --insecure
再到下载pip安装包,解压到某个位置,我这里下载的是9.0.0版本,然后就可以安装了:
wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9tar -xf pip-9.0.1.tar.gzcd pip-9.0.1python setup.py install
创建连接(否则会报错提示“命令不存在”)
ln -s /usr/local/python2.7/bin/pip /usr/bin/pip
至此pip安装完成!
如果安装pip时报如下错误:ImportError: cannot import name HTTPSHandle
执行 yum install sqlite-devel
python2.7 方案解决
>>> import sqlite3
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/-3.5.0/python350/lib/python3.5/sqlite3/__init__.py", line 23, in <module> from sqlite3.dbapi2 import * File "/opt/-3.5.0/python350/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module> from _sqlite3 import *
1
find / -name _sqlite*.so
/usr/lib64/python2.6/lib-dynload/_sqlite3.so
2#
whereis python2.7
python2: /usr/bin/python2.7 /usr/bin/python2 /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python2.7 /usr/local/bin/python2.7-config /usr/local/bin/python2 /usr/local/lib/python2.7 /usr/include/python2.6
3
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/lib-dynload/_sqlite3.so
参考:https://www.cnblogs.com/cnlihao/p/7069776.html
参考:https://www.cnblogs.com/saolv/p/7041067.html