Linux系统默认自带python2.6的版本,这个版本被系统很多程序所依赖,所以建议不要轻易删除,除非你能解决其他程序的依赖问题。如果使用最新的Python3需要进行编译安装源码包,这样就对系统默认的包没有任何影响。

  1. [root@test-c2c-console01 ~]# cat /etc/redhat-release
  2. CentOS release 6.6 (Final)
  3. [root@test-c2c-console01 ~]# uname -a
  4. 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
  5. [root@test-c2c-console01 ~]# python -V
  6. Python 2.6.6

Python官网下载pthon3源码包,https://www.python.org/

选择自己需要的版本

选择源码包

下载到本地然后上传到linux或者复制下载链接直接通过wget下载

  1. [root@test-c2c-console01 tools]# wget -q https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz
  2. [root@test-c2c-console01 tools]# ll Python-3.5.2.tgz
  3. -rw-r--r-- 1 root root 20566643 Jun 26 2016 Python-3.5.2.tgz

解压并安装

  1. [root@test-c2c-console01 tools]# tar xf Python-3.5.2.tgz
  2. [root@test-c2c-console01 tools]# cd Python-3.5.2
  3. [root@test-c2c-console01 Python-3.5.2]# ./configure --prefix=/application/Python-3.5.2/ #指定安装目录
  4. [root@test-c2c-console01 Python-3.5.2]# make && make install

创建软连接

  1. [root@test-c2c-console01 Python-3.5.2]# cd /application/
  2. [root@test-c2c-console01 application]# ln -s Python-3.5.2/ Python3
  3. [root@test-c2c-console01 application]# ll
  4. total 4
  5. lrwxrwxrwx 1 root root 13 Mar 1 09:08 Python3 -> Python-3.5.2/
  6. drwxr-xr-x 6 root root 4096 Mar 1 09:03 Python-3.5.2

到此python3就安装好了,启动pyhon3。

  1. [root@test-c2c-console01 application]# /application/Python3/bin/python3
  2. Python 3.5.2 (default, Mar 1 2017, 09:02:01)
  3. [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>>

由于这样启动比较麻烦可以通过配置环境变量解决。

  1. [root@test-c2c-console01 application]# vim /etc/profile # 文件末尾添加python3路径
  2. PATH="/application/Python3/bin/:$PATH"
  3. [root@test-c2c-console01 application]# source /etc/profile # 更新环境变量
  4. [root@test-c2c-console01 application]# which python3
  5. /application/Python3/bin/python3
  6. [root@test-c2c-console01 application]# which python
  7. /usr/bin/python
  8. [root@test-c2c-console01 application]# python3 -V
  9. Python 3.5.2
  10. [root@test-c2c-console01 application]# python -V
  11. Python 2.6.6

启动系统默认的python

  1. [root@test-c2c-console01 application]# python
  2. Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
  3. [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>>

启动python3

  1. [root@test-c2c-console01 application]# python3
  2. Python 3.5.2 (default, Mar 1 2017, 09:02:01)
  3. [GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>>

 

Python开发【初始篇】:Linux下安装Python3的更多相关文章

  1. 【转】在Linux下安装python3

    原文链接:http://www.cnblogs.com/feng18/p/5854912.html 1.linux下安装python3 a. 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wg ...

  2. Python3.x:Linux下安装python3.6

    Python3.x:Linux下安装python3.6 下载 #先进入download文件夹 cd /home/download #输入命令(下载到当前目录) wget https://www.pyt ...

  3. Linux下安装Python3.3.0

    Linux下安装Python3.3.0_路易_新浪博客 Linux下安装Python3.3.0 (2013-01-08 11:45:37)

  4. linux下安装python3(转)

    一.Linux下安装Python 二.Linux下Python安装完成后如何使用pip命令 三.Linux下Python安装完成后如何使用yum命令 四.Linux下安装Anaconda 五.Linu ...

  5. Linux下安装python3.3.2及configrue、make、make install

    一.安装python3.3.2 raspberry的/usr/local/src目录没有权限,可执行如下命令 pi@raspberrypi:~$ sudo chmod -R 777 /usr/loca ...

  6. python 基础1.1--windows/linux 下安装python

    一.windows下安装python 1>windows上python后缀是.msi的,下载下来后,直接双击运行.会在c盘生成python.exe的文件,把python.exe的文件加入到win ...

  7. Linux下安装Python3.6.8并安装包

    一.问题在Linux下面安装Python3.6.8,由于在Linux中的Python是2.7.x的版本因此,我们需要在Linux中新下载一个Python 二.解决1.python的安装(1)下载包利用 ...

  8. 环境准备—之—linux下安装python3和pip3

    转自 上海悠悠 https://www.cnblogs.com/yoyoketang/p/10195102.html 前言 centos7 自带有 python,但是却是 python2 版本的 py ...

  9. Linux下安装python3环境搭建

    Linux下python3环境搭建 Linux安装软件有哪些方式? rpm软件包 手动安装 拒绝此方式 需要手动解决依赖关系 yum自动化安装 自动处理依赖关系 非常好用 源代码编译安装,可自定义的功 ...

  10. 37、linux下安装python3.6和django

    37.1.安装python: 1.python介绍: python是一种面向对象的,解释型的计算机语言,它的特点是语法简介,优雅,简单易学.1989年诞生,Guido(龟叔)开发. 编译型语言:代码在 ...

随机推荐

  1. python excel表格操作

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. 你真的理解了for循环吗?反正我是没有

    for循环的执行步骤 咱们先来看一个有意思的关于for循环的程序 public class TestFor { public static void main(String[] args) { int ...

  3. About Gnu Linker2

    3.5.1 Simple Assignments symbol = expression ; symbol += expression ; The first case will define sym ...

  4. qnx gpio

    in order to set gpio in qnx, you can use msmgpiotool # msmgpiotool gpiotool usage: gpiotool <comm ...

  5. springboot项目如何打包成war包

    一.修改打包形式 在pom.xml里设置 <packaging>war</packaging> 二.移除嵌入式tomcat插件 在pom.xml里找到spring-boot-s ...

  6. webservice之jax-ws实现方式

    1.什么是webservice? webservice是一种远程资源调用技术,它的实现方式主要分为两种,第一种是jaxws方式,它是面向方法的,它的数据类型是xml是基于soap实现传输:第二种是ja ...

  7. js对象原型prototype

    javascript中的每个对象都有prototype属性,Javascript中对象的prototype属性的解释是:返回对象类型原型的引用. 每一个构造函数都有一个属性叫做原型 1.1. 原型法设 ...

  8. Git操作相关记录

    1. 本地更新fork来的项目,与原项目同步更新 git remote add upstream <origin_repo_addr> git remote -v git fetch up ...

  9. html+css+jq随记

    随便写个博客吧,记录一下自己的历程,今天忽然用自己好久不用的jq还做项目,并且从零开始搭建,让自己慌乱不已啊!遇到了如下问题 1.ios端点击闪屏的问题,解决办法如下 在body上添加 -webkit ...

  10. shell脚本实现telnet测试服务端口

    备注,使用方法:当前目录下要存在需要测试的地址端口的文件ip.txt,例子:cat ip.txt141.12.65.17 7500 #!/bin/bashcur_dir=$(pwd)ipfile=$c ...