文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

升级python2.6.6到python

2023-01-31 07:21

关注

服务器环境为Centos6.8,python为默认的2.6.6版本

python2.6.6 升级到python2.7.14,此处不再描述
可以参考如下文档升级:
https://blog.csdn.net/see_you_see_me/article/details/78550977

升级Python2.7导致使用pip等命令安装模块失败,报错如下:

#pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 5, in <module>
    from pkg_resources import load_entry_point
ImportError: No module named pkg_resources

解决办法可以参考下面的文档,此处也不在详细描述了:
http://linuxsogood.org/816.html

在一外个国人的网站上找到了解决方案:

#curl -O http://python-distribute.org/distribute_setup.py
#/usr/local/pyton2.7/bin/python distribute_setup.py

提示:distribute_setup.py这个脚本文件内容可以找我要

#/usr/local/python2.7/bin/easy_install pip
#/usr/local/python2.7/bin/pip -V
[root@localhost ~]#  /usr/local/python2.7/bin/python distribute_setup.py
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.49.tar.gz
Traceback (most recent call last):
  File "distribute_setup.py", line 537, in <module>
    sys.exit(main())
  File "distribute_setup.py", line 533, in main
    tarball = download_setuptools(download_base=options.download_base)
  File "distribute_setup.py", line 206, in download_setuptools
    src = urlopen(url)
  File "/usr/local/python2.7/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/python2.7/lib/python2.7/urllib2.py", line 435, in open
    response = meth(req, response)
  File "/usr/local/python2.7/lib/python2.7/urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/python2.7/lib/python2.7/urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "/usr/local/python2.7/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/local/python2.7/lib/python2.7/urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: SSL is required

[root@localhost ~]# grep DEFAULT_URL distribute_setup.py
DEFAULT_URL = "https://pypi.python.org/packages/source/d/distribute/"
修改此处的地址为:https

[root@localhost ~]#  /usr/local/python2.7/bin/python distribute_setup.py
。。。。。。。。。。。。。。。。。
。。。。。。。。。。。。。。。。。
Installing easy_install script to /usr/local/python2.7/bin
Installing easy_install-2.7 script to /usr/local/python2.7/bin

Installed /usr/local/python2.7/lib/python2.7/site-packages/distribute-0.6.49-py2.7.egg
Processing dependencies for distribute==0.6.49
Finished processing dependencies for distribute==0.6.49
After install bootstrap.
Creating /usr/local/python2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
Creating /usr/local/python2.7/lib/python2.7/site-packages/setuptools.pth
[root@localhost ~]# echo $?
0
[root@localhost ~]# find / -name 'easy_install'
/usr/local/python2.7/bin/easy_install
/usr/bin/easy_install

使用新版本的python来运行这个脚本,这个会自动安装出来一个easy_install,然后使用这个新的easy_install来安装pip就可以了!

error: Could not find suitable distribution for Requirement.parse('pip')

[root@localhost ~]# /usr/local/python2.7/bin/easy_install pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')

解决文档:https://blog.csdn.net/sunnywuxian/article/details/82870803
解决文档:https://pip.readthedocs.io/en/stable/installing/
解决过程如下:

[root@localhost ~]# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 
[root@localhost ~]# python get-pip.py
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df8e8583ea85385d51125dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 151kB/s 
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/96/ba/a4702cbb6a3a485239fbe9525443446203f00771af9ac000fa3ef2788201/wheel-0.33.1-py2.py3-none-any.whl
Installing collected packages: pip, wheel
  The script wheel is installed in '/usr/local/python2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-19.0.3 wheel-0.33.1
[root@localhost ~]# /usr/local/python2.7/bin/easy_install pip
Searching for pip
Best match: pip 19.0.3
Adding pip 19.0.3 to easy-install.pth file
Installing pip script to /usr/local/python2.7/bin
Installing pip3.7 script to /usr/local/python2.7/bin
Installing pip3 script to /usr/local/python2.7/bin

Using /usr/local/python2.7/lib/python2.7/site-packages
Processing dependencies for pip
Finished processing dependencies for pip
[root@localhost ~]# echo $?
[root@localhost ~]#  /usr/local/python2.7/bin/pip -V
pip 19.0.3 from /usr/local/python2.7/lib/python2.7/site-packages/pip (python 2.7)
[root@localhost ~]# 

到此处pip命令成功安装

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯