安装python | python2.7.12一键脚本 & python3.6.0一键脚本。

  • 首页 > 教程
  • 作者:jaz
  • 时间: 2017年3月12日 18:32
  • 字数:6561 个
  • 字号:
  • 评论:1 条
  • 浏览:10798 次
  • 百度:百度已收录
  • 分类: 教程
  • 时间:2017-3-12 18:32 热度:10798° 评论:1 条 


    python.png

    最近因为有几个应用需要用到Python,作为折腾了一下安装Python。


    • 安装
    • 使用
    • 其他一键脚本


                                                                                               

    安装

    • 安装python2.7.x
    在网上找了很多教程,觉得有两篇比较好的
    ①秋大的
    CentOS 6.8安装Python2.7.13 | 秋水逸冰  https://teddysun.com/473.html
    备份页
    ②fazero博客的一键脚本(方便)
    Centos升级Python 2.7.12并安装最新pip | fazero  https://blog.fazero.me/2016/10/13/centos-update-python/
    备份页

    具体自己查看。

    • 安装python3.x
    这里有一篇安装python3.5的,教程中的3.5可以改为其他3.x.x版本。
    注意:文中有几处  - 减号,由于格式/或编码问题,会显示错,请自行更改。

    另外为了减少折腾,请先安装必需包

    centos:

    yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel gcc

    Debian/Ubuntu:


    apt-get update
    apt-get install -y zlib1g-dev gcc make libssl-dev openssl libreadline-dev

    python3.5学习笔记:linux6.4 安装python3 pip setuptools - tjj93622的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/tjj93622/article/details/52608087

    备份页

    使用

                                                                                               

    在使用过程中,遇到一些问题,只是小白的我,只能一步一步找办法解决。

    问题一:
    python2.7中使用pip出现
    Exception:
    Traceback (most recent call last):
      File "/usr/local/python2.7.12/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    ....................
      File "/usr/local/python2.7.12/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1577, in _get
        with open(path, 'rb') as stream:
    IOError: [Errno 2] No such file or directory: '/usr/local/python2.7.12/lib/python2.7/site-packages/six-1.10.0.dist-info/METADATA'
    原因:估计是python2.7版本中的pip没有升级/缺少文件,小白我不懂。
    解决方法:
    确保软连接创建没有错,运行python -V的版本是2.7.X


    方法①:执行 (我修复成功了)

    python -m pip install -U --force-reinstall pip

    参考:http://blog.csdn.net/scdxmoe/article/details/53504117


    方法②:使用easy_install 命令安装pip
    #安装setuptool,easy_install 命令就会被安装在 /usr/local/bin 目录下
    wget https://bootstrap.pypa.io/ez_setup.py -O - | python
    #为新版 Python 安装 pip

    easy_install pip 


    方法③:重新编译安装pip,如果提示要安装setuptools,请先安装setuptools
    #安装pip 
    wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb
    tar -zxvf pip-8.0.2.tar.gz
    cd pip-8.0.2
    python setup.py build
    python setup.py install
    #如果没有意外的话,pip安装完成。


    #安装setuptools

    #安装pip前需要前安装setuptools
    wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
    tar -zxvf setuptools-19.6.tar.gz
    cd setuptools-19.6
    python setup.py build
    python setup.py install 

    方法④:找百度,找谷歌,找老司机


    问题二:
    There was a problem importing one of the Python modules
    required to run yum. The error leading to this problem was:

       No module named yum

    Please install a package which provides this module, or
    verify that the module is installed correctly.

    It's possible that the above module doesn't match the
    current version of Python, which is:
    2.7.3 (default, Nov 24 2016, 00:21:41) 
    [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]


    If you cannot solve this problem yourself, please go to 

    the yum faq at:

      http://yum.baseurl.org/wiki/Faq


    原因:猜测yum调用了高版本的python。


    解决方法:


    #查看系统中的python版本(有两个)
    whereis python
    #返回 python: /usr/bin/python2.7 /usr/bin/python2.6 /usr/bin/python /usr/lib/python2.6 /usr/lib64/python2.6 /usr/include/python2.6 /usr/local/python2.7 /usr/share/man/man1/python.1.gz
    查看Python使用中的版本
    python -V
    #返回Python 2.7.3
    vi /usr/bin/yum  

    #!/usr/bin/python
    改为:
    #!/usr/bin/python2.6


    问题三:
    在ubuntu16.04上编译安装Python3.6后,使用pip出现错误
    Exception:
    Traceback (most recent call last):
      File "/tmp/tmpglkLpE/pip.zip/pip/basecommand.py", line 215, in main
    .......................................
      File "/tmp/tmpglkLpE/pip.zip/pip/_vendor/distro.py", line 933, in _get_lsb_release_info
    CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1
    解决方法:
    没解决,建议ubuntu16上直接使用apt-get安装
    apt-get update
    apt-get install -y  python3 python3-pip python3-dev  

                                                                                               
    其他一键脚本

    整理一键脚本

    1)update-python2.7.12一键脚本(来自fazero博客):

        适用于centos

    wget http://7xpt4s.com1.z0.glb.clouddn.com/update-python2.7.12.sh && bash update-python2.7.12.sh


    2)update-python3.6.0一键脚本(我仿写)

        已在centos6/7、Debian7/8、Ubuntu14上测试

    wget --no-check-certificate https://raw.githubusercontent.com/kmm996/update-python/master/update-python3.6.0.sh && bash update-python3.6.0.sh


    Ubuntu系统自带Python3软件包,安装pip时,注意python与python3、pip与pip3的区分

    apt-get install -y  python3 python3-pip python3-dev
    python3 -V
    pip3 -V


    ③手动编译安装setuptools、pip3

    #安装pip前需要前置安装setuptools
    wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26
    tar -zxvf setuptools-19.6.tar.gz
    cd setuptools-19.6
    python3 setup.py build
    python3 setup.py install 

    #安装pip
    wget --no-check-certificate https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
    tar -zxvf pip-9.0.1.tar.gz
    cd pip-9.0.1
    python3 setup.py build
    python3 setup.py install

    #如果没有意外的话,pip安装完成。


    参考:

    https://teddysun.com/473.html

    https://blog.fazero.me/2016/10/13/centos-update-python/

    http://blog.csdn.net/tjj93622/article/details/52608087

    http://blog.csdn.net/scdxmoe/article/details/53504117

     

    End、

    正文到此结束
    您阅读这篇文章共花了: 
    本文链接://blog.jialezi.net/?post=30
    版权声明:若无特殊注明,本文皆为《jaz》原创,转载请保留文章出处。
    捐赠支持:如果觉得这篇文章对您有帮助,请“扫一扫”鼓励作者!

    热门推荐

    Hello! How do you see it?

    你还可以输入250 / 250 个字

    嘻嘻 大笑 可怜 吃惊 害羞 调皮 鄙视 示爱 大哭 开心 偷笑 嘘 奸笑 委屈 抱抱 愤怒 思考 日了狗

    已有1条吐槽

    匿名

    2023-07-17 18:56 IANA保留地址
    发帖软件 www.teamczyx.com
     未知操作系统   未知浏览器

    返回顶部    返回首页    手气不错    捐赠支持         
    版权所有:Jialezi `s blog    站点维护:    +主题:海云彩色