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


升级步骤

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

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

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

加入到 path 对应的目录 :

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

安装 setuptools

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

安装 PIP

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

修复 yum 工具

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

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

修改 yum中的python

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

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


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

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

[root@localhost opt]# pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-o53eKA/mysql-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-o53eKA/mysql-python/ [root@localhost opt]# yum install mysql-devel.x86_64
[root@localhost opt]# pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: mysql-python
Running setup.py bdist_wheel for mysql-python ... done
Stored in directory: /root/.cache/pip/wheels/38/a3/89/ec87e092cfb38450fc91a62562055231deb0049a029054dc62
Successfully built mysql-python
Installing collected packages: mysql-python
Successfully installed mysql-python-1.2.5
[root@localhost opt]# ipython
Python 2.7.8 (default, Oct 4 2016, 17:31:33)
Type "copyright", "credits" or "license" for more information. IPython 5.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details. 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. STL之容器适配器priority_queue

    priority_queue(优先队列)是一个拥有权值观念的queue,它允许加入新元素,删除旧元素,审视元素值等功能.由于这是一个queue,所以只允许在底端加入元素,并从顶端取出元素, 除此之外别 ...

  2. CSS3学习笔记1-选择器和新增属性

    前言:之前自学了一些关于CSS3的知识,在学习过程中也遇到过坑,不过总算磕磕绊绊的学习完了关于CSS3的相关知识,于是最近把之前的笔记和代码整理了一下,也算是一个对CSS3知识的回顾复习吧,也希望能够 ...

  3. [react native] react-native-tab-navigator在子Component中隐藏

    因为文档只列出了TabBarIOS, 不支持Android,所以github上找到这个组件. 先说下我的页面构造:  入口文件 —> 注册组件(包含Navigator, 跳转到欢迎页)—> ...

  4. UITableViewCell重用导致内容混乱方案

    UITableViewCell *cell=nil; static NSString *reuse=@"cell"; if (cell==nil) { cell=[[UITable ...

  5. VA的自动补全Snippet

    开始旅程 如果您想要自定义补全,比如在使用UE4框架时,想输入一个方法的注释模板,可以这么做. 方法1:点击VAssistX -> insert VA Snippet -> Edit VA ...

  6. 用Python读写Excel文件(转)

    原文:google.com/ncr 虽然天天跟数据打交道,也频繁地使用Excel进行一些简单的数据处理和展示,但长期以来总是小心地避免用Python直接读写Excel文件.通常我都是把数据保存为以TA ...

  7. java性能调优工具

    windows调优工具: 任务管理器(ctrl+alt+delete或).资源管理器(任务管理器->性能进入或运行resmon.exe):JVM分析工具Jconsole,jProfile,Vis ...

  8. WPF的二维绘图(一)——DrawingContext

    DrawingContext比较类似WinForm中的Graphics 类,是基础的绘图对象,用于绘制各种图形,它主要API有如下几种: 绘图API 绘图API一般形为DrawingXXX系列,常用的 ...

  9. 以练代学之shell入门(一)

    5年前的时候,开始接触linux操作系统,接触的第一步就是学习shell脚本.用小脚本以连代学入了门. 1) 9*9乘法输出 2) 检验主机的服务是否启动 3) 冒泡排序 4) 备份当时team服务器 ...

  10. Winform 五种常用对话框控件的简单使用

    OpenFileDialog(打开文件对话框)FolderBrowserDialog(浏览文件夹对话框)SaveFileDialog(保存文件对话框)ColorDialog(颜色选择对话框)FontD ...