背景:
我最近在学习Python,自己电脑配置较低,不想搞虚拟机了。于是在某云平台上申请了台云服务器。操作系统为:CentOS6.8,但发现系统默认带的Python版本为Python 2.6。版本是有点老了,我想把服务器上的Python版本升级到Python2.7,于是乎在网上搜了相关资料,准备升级到Python2.7.13版本(可以官网去下载:https://www.python.org/downloads/source/ )。
安装过程参考以下文章:
文章1:https://segmentfault.com/a/1190000014598286
文章2:https://www.linuxidc.com/Linux/2018-07/153195.htm
文章3:https://blog.csdn.net/qq_33290422/article/details/80986984
安装过程很顺利,安装完Python及pip、easy_install等。
但在验证执行 easy_install命令时报错如下:
[root@VM_0_15_centos downloads]# easy_install
Traceback (most recent call last):
File "/usr/bin/easy_install",line 11,in
load_entry_point('setuptools==33.1.1','console_scripts','easy_install')()
File "/chen/mysoft/python/lib/python2.7/site-packages/pkg_resources/__init__.py",line 489,in load_entry_point
return get_distribution(dist).load_entry_point(group,name)
File "/chen/mysoft/python/lib/python2.7/site-packages/pkg_resources/__init__.py",line 2793,in load_entry_point
return ep.load()
File "/chen/mysoft/python/lib/python2.7/site-packages/pkg_resources/__init__.py",line 2411,in load
return self.resolve()
File "/chen/mysoft/python/lib/python2.7/site-packages/pkg_resources/__init__.py",line 2417,in resolve
module = __import__(self.module_name,fromlist=['__name__'],level=0)
File "build/bdist.linux-x86_64/egg/setuptools/command/easy_install.py",line 51,in
File "build/bdist.linux-x86_64/egg/setuptools/archive_util.py",in
ImportError: cannot import name ContextualZipFile
于是网上搜了下,参考了一下两篇文章:
https://stackoverflow.com/questions/48051219/cannot-import-name-contextualzipfile
https://blog.csdn.net/Lee_Natuo/article/details/80376682
参照上述文章中提到的解决方案,搞了一通。很不幸,解决不了问题。
但是初步可以断定的是,setuptools安装的版本有问题。
于是试着升级setuptools,执行命令如下:
[root@VM_0_15_centos downloads]# pip install setuptools
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 maintainedpport for Python 2.7.
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Requirement already satisfied: setuptools in /chen/mysoft/python/lib/python2.7/site-packages (40.8.0)
啥???提示版本40.8.0已经是最新的了。卧槽,我在安装easy_install的时候,执行完 python ez_setup.py 时,默认安装的明明是 setuptools-33.1.1 呀。
到Python的包管理目录下看看去吧:(我的安装路径:/chen/mysoft/python/lib/python2.7/site-packages)
[root@VM_0_15_centos site-packages]# ls
easy-install.pth easy_install.pyc Pillow-5.4.1.dist-info pip-19.0.3.dist-info README setuptools-33.1.1-py2.7.egg setuptools.pth
easy_install.py PIL pip pkg_resources setuptools setuptools-40.8.0.dist-info wheel
看完后这都什么呀,我这暴脾气来了,一顿操作猛如虎,如下:
cd /chen/mysoft/python/lib/python2.7/site-packages
rm -rf setuptools*
重新安装setuptools吧:
[root@VM_0_15_centos site-packages]# pip install setuptools
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 maintainedpport for Python 2.7.
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Collecting setuptools
Downloading http://mirrors.tencentyun.com/pypi/packages/d1/6a/4b2fcefd2ea0868810e92d519dacac1ddc64a2e53ba9e3422c3b62b378a6/setuptools-4
100% |████████████████████████████████| 583kB 60.6MB/s
Installing collected packages: setuptools
Successfully installed setuptools-40.8.0
安装后,再试下吧:
[root@VM_0_15_centos setuptools]# easy_install beautifulsoup4
Searching for beautifulsoup4
Reading http://mirrors.tencentyun.com/pypi/simple/beautifulsoup4/
Downloading http://mirrors.tencentyun.com/pypi/packages/8b/0e/048a2f88bc4be5e3697df9dc1f7b9d5c9c75be62676feeeb91d2e896c5ea/beautifulsoup47e4ef5
......
Finished processing dependencies for beautifulsoup4
哼~,就这么一通操作,问题搞定了。开森~
原文地址:https://blog.csdn.net/B11050729/article/details/88896798
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。