CentOS 6.X 自带的python版本是 2.6 , 由于工作需要,很多时候需要2.7版本。所以需要进行版本升级。由于一些系统工具和服务是对 Python 有依赖的,所以升级 Python 版本需要注意。


升级步骤

如何欢乐的,没有痛苦的升级python版本 ,往下看 …

更新系统和开发工具集
  1. 更新指令
  2. [root@localhost ~]# yum -y update
  3. [root@localhost ~]# yum groupinstall -y 'development tools'
  4. 另外还需要安装 python 工具需要的额外软件包 SSL, bz2, zlib
  5. [root@localhost ~]# yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget
  6. 源码安装Python 2.7.x
  7. [root@localhost ~]# wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
  8. [root@localhost ~]# xz -d Python-2.7.8.tar.xz
  9. [root@localhost ~]# tar -xvf Python-2.7.8.tar
安装详情:
  1. # 进入目录:
  2. [root@localhost ~]# cd Python-2.7.8
  3. # 运行配置 configure: 加上--enable-shared 以后需要用到libpython 库
  4. [root@localhost ~]# ./configure --enable-shared --prefix=/usr/local
  5. # 编译安装:
  6. [root@localhost ~]# make
  7. [root@localhost ~]# make altinstall
  8. # 检查 Python 版本:
  9. [root@localhost ~]# python2.7 -V
  10. Python 2.7.8
  1. [root@localhost Python-2.7.8]# python2.7 -V
  2. python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
  3. [root@localhost Python-2.7.8]# find /|grep libpython2.7.so.1.0
  4. /opt/Python-2.7.8/libpython2.7.so.1.0
  5. /usr/local/lib/libpython2.7.so.1.0
  6. [root@localhost Python-2.7.8]# cp -a libpython2.7.so.1.0 /usr/lib/
  7. [root@localhost Python-2.7.8]# python2.7 -V
  8. python2.7: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
  9. [root@localhost Python-2.7.8]# ldconfig
  10. [root@localhost Python-2.7.8]# python2.7 -V
  11. Python 2.7.8
  12. [root@localhost Python-2.7.8]#
设置 PATH

为了我们能够方便的使用Python,我们需要设置系统变量或者建立 软连接将新版本的 Python

加入到 path 对应的目录 :

  1. [root@localhost ~]# export PATH="/usr/local/bin:$PATH"
  2. or
  3. [root@localhost ~]# ln -s /usr/local/bin/python2.7 /usr/bin/python
  4. # 检查
  5. [root@localhost ~]# python -V
  6. Python 2.7.8
  7. [root@localhost ~]# which python
  8. /usr/bin/python

安装 setuptools

  1. #获取软件包
  2. [root@localhost ~]# wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz
  3. #解压:
  4. [root@localhost ~]# tar -xvf setuptools-1.4.2.tar.gz
  5. [root@localhost ~]# cd setuptools-1.4.2
  6. # 使用 Python 2.7.8 安装 setuptools
  7. [root@localhost ~]# python2.7 setup.py install

安装 PIP

  1. [root@localhost ~]# curl --insecure https://bootstrap.pypa.io/get-pip.py | python2.7 -

修复 yum 工具

此时yum应该是失效的,因为此时默认python版本已经是2.7了。而yum需要的是2.6 所以:

  1. [root@localhost ~]# which yum
  2. /usr/bin/yum

修改 yum中的python

  1. [root@localhost ~]# vi /usr/bin/yum
  2. #!/usr/bin/python2.6
  3. ……

将第一行 #!/usr/bin/python 改为 #!/usr/bin/python2.6此时yum就ok啦


安装ipython
  1. yum 安装
  1. [root@localhost ~]# yum install ipython -y
  1. pip install ipython #前提你有安装setuptools才有pip
  1. [root@localhost ~]# pip install ipython
  1. [root@localhost ~]# ipython
  2. /usr/local/lib/python2.7/site-packages/IPython/frontend.py:21: ShimWarning: The top-level `frontend` package has been deprecated. All its subpackages have been moved to the top `IPython` level.
  3. "All its subpackages have been moved to the top `IPython` level.", ShimWarning)
  4. /usr/local/lib/python2.7/site-packages/IPython/core/history.py:228: UserWarning: IPython History requires SQLite, your history will not be saved
  5. warn("IPython History requires SQLite, your history will not be saved")
  6. Python 2.7.8 (default, Oct 18 2016, 10:37:37)
  7. Type "copyright", "credits" or "license" for more information.
  8. IPython 5.1.0 -- An enhanced Interactive Python.
  9. ? -> Introduction and overview of IPython's features.
  10. %quickref -> Quick reference.
  11. help -> Python's own help system.
  12. object? -> Details about 'object', use 'object??' for extra details.
  13. In [1]: print ( "hello word!" )
  14. hello word!
扩展python模块
  1. pip install requests
  2. pip install Flask
  3. pip install fabric
  4. pip install psutil
  5. pip install IPy
  6. pip install dnspython
  7. pip install MySQL-python
  8. #1. yum install mysql-devel.x86_64
  9. #2. pip install mysql-python

python数据库安装时错误解决办法:

  1. [root@localhost opt]# pip install mysql-python
  2. Collecting mysql-python
  3. Using cached MySQL-python-1.2.5.zip
  4. Complete output from command python setup.py egg_info:
  5. sh: mysql_config: command not found
  6. Traceback (most recent call last):
  7. File "<string>", line 1, in <module>
  8. File "/tmp/pip-build-o53eKA/mysql-python/setup.py", line 17, in <module>
  9. metadata, options = get_config()
  10. File "setup_posix.py", line 43, in get_config
  11. libs = mysql_config("libs_r")
  12. File "setup_posix.py", line 25, in mysql_config
  13. raise EnvironmentError("%s not found" % (mysql_config.path,))
  14. EnvironmentError: mysql_config not found
  15. ----------------------------------------
  16. Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-o53eKA/mysql-python/
  17. [root@localhost opt]# yum install mysql-devel.x86_64
  18. [root@localhost opt]# pip install mysql-python
  19. Collecting mysql-python
  20. Using cached MySQL-python-1.2.5.zip
  21. Building wheels for collected packages: mysql-python
  22. Running setup.py bdist_wheel for mysql-python ... done
  23. Stored in directory: /root/.cache/pip/wheels/38/a3/89/ec87e092cfb38450fc91a62562055231deb0049a029054dc62
  24. Successfully built mysql-python
  25. Installing collected packages: mysql-python
  26. Successfully installed mysql-python-1.2.5
  27. [root@localhost opt]# ipython
  28. Python 2.7.8 (default, Oct 4 2016, 17:31:33)
  29. Type "copyright", "credits" or "license" for more information.
  30. IPython 5.1.0 -- An enhanced Interactive Python.
  31. ? -> Introduction and overview of IPython's features.
  32. %quickref -> Quick reference.
  33. help -> Python's own help system.
  34. object? -> Details about 'object', use 'object??' for extra details.
  35. In [1]: import MySQLdb

linux python升级和ipython的安装的更多相关文章

  1. python升级pip和Django安装

    1.centos7默认python版本为2.7.5,现升级到3.6.0 2.wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz ...

  2. linux python升级及全局环境变量设置

    1.下载pythonwget https://www.python.org/ftp/python/3.4.5/Python-3.4.5.tgz 或者去官网下载压缩包 2.安装python3依赖yum ...

  3. Linux下升级python

    本文的Linux系统为CentOS 7 64 在Linux系统的下载文件夹中邮件打开终端,输入命令: wget http://www.python.org/ftp/python/3.4.4/Pytho ...

  4. Linux下升级Python到3.5.2版本

    原文出处:https://www.cnblogs.com/tssc/p/7762998.html 本文主要介绍在Linux(CentOS)下将Python的版本升级为3.5.2的方法 众所周知,在20 ...

  5. Ubutnu linux 下升级python版本,以2.x升级到3.x为例

    Linux操作系统一般 都会自带python,但是python版本会比主流低,故升级python, 主要思路:自带的python的链接link文件是在/usr/bin 下,采用sudo apt-get ...

  6. Linux下升级安装Python-3.6.2版本

    本文主要介绍在Linux(CentOS)下将Python的版本升级为3.6.2的方法 众所周知,在2020年python官方将不再支持2.7版本的python,所以使用3.x版本的python是必要的 ...

  7. linux服务器升级python版本(python2与python3共存)

    linux服务器升级python版本 ######################################## 第一步先安装sqlite-devel,因为python2也有这个,python3 ...

  8. linux下面升级 Python版本并修改yum属性信息

    最近需要在linux下使用python,故需要升级一下python版本,上网查询了一下相关资料,更新了一下linux下面的python环境,记录如下: linux下面升级 Python版本并修改yum ...

  9. 将linux默认python升级到2.7.4版本

    第一步:下载python2.7.4版本源码: wget http://python.org/ftp/python/2.7.4/Python-2.7.4.tgz 解压文件 [aa@localhost ~ ...

随机推荐

  1. java多线程处理

    package com.copyFile; import java.io.BufferedReader;import java.io.File;import java.io.FileReader;im ...

  2. UIViewController生命周期

    UIViewController生命周期

  3. java学习第17天(TreeSet HashSet)

    Set集合的特点(与ArrayList相比) 无序,唯一 主要学习它的两个子类 HashSet集合 A:底层数据结构是哈希表(是一个元素为链表的数组) B:哈希表底层依赖两个方法:hashCode() ...

  4. python中的浅拷贝和深拷贝

    1.赋值语句 a = 'abc' b = a print id(a) print id(b) # id(a):29283464 # id(b):29283464 通过简单的复制,我们可以看到,a b其 ...

  5. Android 6.0权限适配

    targetSdkVersion 23以上,必须适配新的权限模式 安卓6.0及之后,权限分为三类  1.不涉及隐私的正常权限,如innernet2.危险权限 3.特殊权限 system_alert_w ...

  6. Android Activity 四种启动模式

    task和back stack(任务和回退栈) 任务启动,task被加入到回退栈的栈顶,返回的时候回退栈的栈顶任务会被弹出,并被销毁,栈中的前一任务恢复运行,当activity销毁是,系统不会保留ac ...

  7. 学生信息管理系统(自己辛辛苦苦做了几天,虽然简陋,也凑合吧,bug不算太严重,主要是格式不太很完美)

    /*学生成绩管理系统V3.0(链表版)某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入).使用链表编程成实现如下菜单驱动的学生成绩管理系统.1.从文件读入每 ...

  8. php开发环境

    php一般使用xampp(apache+mysql+php+perl)部署,下载地址https://www.apachefriends.org/zh_cn/index.html.本文不用集成包,搭建P ...

  9. modelsim(3) - summary ,issue,tips

    1) the OEM of modelsim is 10 times slower than offical questa 2)how to the file full path in the mod ...

  10. 《CoffeeScript应用开发》学习:第五章 CoffeeScript中的类

    在CoffeeScript中定义类 在CoffeeScript中,使用class定义类,使用关键字new实例化对象. 给类绑定方法 class Airplane takeOff: -> cons ...