Python开发【初始篇】:Linux下安装Python3
Linux系统默认自带python2.6的版本,这个版本被系统很多程序所依赖,所以建议不要轻易删除,除非你能解决其他程序的依赖问题。如果使用最新的Python3需要进行编译安装源码包,这样就对系统默认的包没有任何影响。
- [root@test-c2c-console01 ~]# cat /etc/redhat-release
- CentOS release 6.6 (Final)
- [root@test-c2c-console01 ~]# uname -a
- Linux test-c2c-console01.bj 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
- [root@test-c2c-console01 ~]# python -V
- Python 2.6.6
Python官网下载pthon3源码包,https://www.python.org/
选择自己需要的版本
选择源码包
下载到本地然后上传到linux或者复制下载链接直接通过wget下载
- [root@test-c2c-console01 tools]# wget -q https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
- [root@test-c2c-console01 tools]# ll Python-3.5.2.tgz
- -rw-r--r-- 1 root root 20566643 Jun 26 2016 Python-3.5.2.tgz
解压并安装
- [root@test-c2c-console01 tools]# tar xf Python-3.5.2.tgz
- [root@test-c2c-console01 tools]# cd Python-3.5.2
- [root@test-c2c-console01 Python-3.5.2]# ./configure --prefix=/application/Python-3.5.2/ #指定安装目录
- [root@test-c2c-console01 Python-3.5.2]# make && make install
创建软连接
- [root@test-c2c-console01 Python-3.5.2]# cd /application/
- [root@test-c2c-console01 application]# ln -s Python-3.5.2/ Python3
- [root@test-c2c-console01 application]# ll
- total 4
- lrwxrwxrwx 1 root root 13 Mar 1 09:08 Python3 -> Python-3.5.2/
- drwxr-xr-x 6 root root 4096 Mar 1 09:03 Python-3.5.2
到此python3就安装好了,启动pyhon3。
- [root@test-c2c-console01 application]# /application/Python3/bin/python3
- Python 3.5.2 (default, Mar 1 2017, 09:02:01)
- [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>>
由于这样启动比较麻烦可以通过配置环境变量解决。
- [root@test-c2c-console01 application]# vim /etc/profile # 文件末尾添加python3路径
- PATH="/application/Python3/bin/:$PATH"
- [root@test-c2c-console01 application]# source /etc/profile # 更新环境变量
- [root@test-c2c-console01 application]# which python3
- /application/Python3/bin/python3
- [root@test-c2c-console01 application]# which python
- /usr/bin/python
- [root@test-c2c-console01 application]# python3 -V
- Python 3.5.2
- [root@test-c2c-console01 application]# python -V
- Python 2.6.6
启动系统默认的python
- [root@test-c2c-console01 application]# python
- Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
- [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>>
启动python3
- [root@test-c2c-console01 application]# python3
- Python 3.5.2 (default, Mar 1 2017, 09:02:01)
- [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>>
posted on 2017-03-01 10:05 yinshoucheng 阅读(1674) 评论(0) 编辑 收藏 举报