博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux python升级和ipython的安装
阅读量:6000 次
发布时间:2019-06-20

本文共 5528 字,大约阅读时间需要 18 分钟。

==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 -VPython 2.7.8
[root@localhost Python-2.7.8]# python2.7 -Vpython2.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 -Vpython2.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 -VPython 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 -VPython 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 Flaskpip install fabricpip install psutilpip install IPypip install dnspythonpip install MySQL-python    #1. yum install mysql-devel.x86_64    #2. pip install mysql-python

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

[root@localhost opt]# pip install mysql-pythonCollecting 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 "
", line 1, in
File "/tmp/pip-build-o53eKA/mysql-python/setup.py", line 17, in
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-pythonCollecting mysql-python Using cached MySQL-python-1.2.5.zipBuilding 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/ec87e092cfb38450fc91a62562055231deb0049a029054dc62Successfully built mysql-pythonInstalling collected packages: mysql-pythonSuccessfully installed mysql-python-1.2.5[root@localhost opt]# ipythonPython 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

转载于:https://www.cnblogs.com/mologa-jie/p/6064779.html

你可能感兴趣的文章
python(56):正则表达式积累
查看>>
发送短信验证码-node+阿里云短信
查看>>
04-爬取单个英雄联盟英雄的符文图片
查看>>
《人员管理》读书笔记
查看>>
判断一棵二叉树是否为二叉搜索树
查看>>
Android屏幕适配解析 - 详解像素,设备独立像素,归一化密度,精确密度及各种资源对应的尺寸密度分辨率适配问题...
查看>>
悟透JavaScript
查看>>
大连东软集团实践报告
查看>>
"蓝桥杯“基础练习:数列特征
查看>>
证明积累
查看>>
233 Matrix
查看>>
深入学习jQuery自定义插件
查看>>
设计模式之适配器模式
查看>>
IDEA 字体设置(转)
查看>>
java无需解压zip压缩包直接读取包内的文件名(含中文)
查看>>
Testing - 软件测试知识梳理 - 理解测试
查看>>
L2TP/IPSec一键安装脚本
查看>>
android以json形式提交信息到服务器
查看>>
CetnOS 6.7安装Hive 1.2.1
查看>>
最短最优升级路径(完美世界2017秋招真题)
查看>>