python环境搭建-Linux系统下python2.6.6升级python3.5.2步骤

[root@template ~]# python -v
# /usr/lib64/python2.6/encodings/utf_8.pyc matches /usr/lib64/python2.6/encodings/utf_8.py
import encodings.utf_8 # precompiled from /usr/lib64/python2.6/encodings/utf_8.pyc
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/usr/lib64/python2.6/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /usr/lib64/python2.6/lib-dynload/readline.so
>>> exit()

Python3.5.2官方网站下载地址

https://www.python.org/downloads/source/

升级为python3.5版本步骤
root@template ~]# cd /home/nulige/tools/ #下载python-3.5.2
[root@template tools]# wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz [root@template tools]# ll
总用量 20104
-rw-r--r-- 1 root root 20566643 6月 26 05:47 Python-3.5.2.tgz #解压到下载目录
[root@template tools]# tar zxvf Python-3.5.2.tgz [root@template tools]# ll
总用量 20108
drwxrwxr-x 16 1000 1000 4096 6月 26 05:38 Python-3.5.2
-rw-r--r-- 1 root root 20566643 6月 26 05:47 Python-3.5.2.tgz
-rwxrwxrwx. 1 root root 13259 5月 8 16:10 system_optimize_scripts.sh #进入解压后的文件夹
[root@template tools]# cd Python-3.5.2 #在编译前先在/usr/local建一个文件夹python3(作为python的安装路径,以免覆盖老的版本)
[root@template Python-3.5.2]# mkdir /usr/local/python3 #开始编译安装
[root@template Python-3.5.2]# ./configure --prefix=/usr/local/python3
make && make installchecking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
中间步骤省略............
checking for --without-gcc... no
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Modules/Setup.config
config.status: creating Misc/python.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup
creating Modules/Setup.local
creating Makefile [root@template Python-3.5.2]# make && make install
中间步骤省略............
if test "x" != "x" ; then \
rm -f /usr/local/python3/bin/python3-32; \
(cd /usr/local/python3/bin; ln -s python3.5-32 python3-32) \
fi
rm -f /usr/local/python3/share/man/man1/python3.1
(cd /usr/local/python3/share/man/man1; ln -s python3.5.1 python3.1)
if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
./python -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS [root@template Python-3.5.2]# echo $?
0
编译完成
################################################
#此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
[root@template Python-3.5.2]# mv /usr/bin/python /usr/bin/python_old #再建立新版本python的软链接
[root@template Python-3.5.2]# ln -s /usr/local/python3/bin/python3 /usr/bin/python #就会显示出python的新版本信息
[root@template Python-3.5.2]# python
Python 3.5.2 (default, Aug 2 2016, 11:35:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit() #<----退出python PS:如果不建立新安装路径python3,而是直接默认安装,则安装后的新python应该会覆盖linux下自带的老版本,也有可能不覆盖,具体看安装过程了,这个大家可以自己试验下,当然如果还想保留原来的版本,那么这种方法最好不过了。 注意事项:
这种方法虽然能安装成功,但会导致yum不能正常使用。 解决方法:
[root@template tools]# cp /usr/bin/yum /usr/bin/yum.backup_2016-08-02 修改第一行参数
vi /usr/bin/yum
把 #!/usr/bin/python 修改为:/usr/bin/python_old

把 #!/usr/bin/python 修改为:/usr/bin/python2.6 #查看版本
[root@template Python-3.5.2]# python --version
Python 3.5.2
上一篇:【javascript】九宫格抽奖组件设计


下一篇:用jQuery编写简单九宫格抽奖