欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 维修 > 下载安装ansible后,缺失pyyaml,pip安装时又出错,升级时又由于时Python2.7,不好升级遇到的一系列问题。

下载安装ansible后,缺失pyyaml,pip安装时又出错,升级时又由于时Python2.7,不好升级遇到的一系列问题。

2024/10/24 3:22:30 来源:https://blog.csdn.net/qq_52983535/article/details/140961356  浏览:    关键词:下载安装ansible后,缺失pyyaml,pip安装时又出错,升级时又由于时Python2.7,不好升级遇到的一系列问题。

经过上一篇文章,我虽然误删了CentOs自带的python和yum,但是我重新将他们恢复了。这里记住默认的python版本是2.7.5。

我使用yum安装好ansible后,检查我的ansible版本的时候,发生了错误,提示没有yaml模块。

1 验证ansible时出错

yum install ansible
[root@yj test]# ansible --version
Traceback (most recent call last):File "/usr/bin/ansible", line 62, in <module>import ansible.constants as CFile "/usr/lib/python2.7/site-packages/ansible/constants.py", line 19, in <module>from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_valueFile "/usr/lib/python2.7/site-packages/ansible/config/manager.py", line 17, in <module>from yaml import load as yaml_load
ImportError: No module named yaml

2 pip安装包时出错

然后我看了网上的教程,提示使用pip去安装pyyaml模块,但是又报错了。

pip install pyyaml
Collecting PyYAMLRetrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out. (read timeout=15)",)': /simple/pyyaml/Could not fetch URL https://pypi.python.org/simple/pyyaml/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618) - skippingCould not find a version that satisfies the requirement PyYAML (from versions: )
No matching distribution found for PyYAML

 这个之后,我尝试了很多种方法,都不成功,然后我把目光瞄准了是否是我的pip有问题。我开始使用pip --version,查看我的pip版本,到达目标位置除时,我发现这个pip时2019年的。这个肯定太老了。

[root@yj test]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)

3 命令升级pip时出错。

下一步,我尝试去升级pip的版本。但是我发现使用命令去升级版本也会出错,也不行,下面是我的一系列尝试,最终还是以失败告终。

[root@yj test]# pip install --upgrade pip
Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618) - skipping
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
You are using pip version 8.1.2, however version 24.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@yj test]# pip install --upgrade --trusted-host  pip
You must give at least one requirement to install (see "pip help install")
You are using pip version 8.1.2, however version 24.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@yj test]# sudo pip install --upgrade --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages
You are using pip version 8.1.2, however version 24.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@yj test]# sudo python -m pip install --upgrade --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f107f4bad90>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pip/
Retrying (Retry(total=3, connect=None, read=None, redirect=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)",)': /simple/pip/
Collecting pipDownloading https://files.pythonhosted.org/packages/4d/87/fb90046e096a03aeab235e139436b3fe804cdd447ed2093b0d70eba3f7f8/pip-24.2.tar.gz (1.9MB)
Exception:
Traceback (most recent call last):File "/usr/lib/python2.7/site-packages/pip/basecommand.py", line 215, in mainstatus = self.run(options, args)File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 307, in runrequirement_set.prepare_files(finder)File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 370, in prepare_filesignore_dependencies=self.ignore_dependencies))File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 587, in _prepare_filesession=self.session, hashes=hashes)File "/usr/lib/python2.7/site-packages/pip/download.py", line 811, in unpack_urlhashes=hashesFile "/usr/lib/python2.7/site-packages/pip/download.py", line 650, in unpack_http_urlhashes)File "/usr/lib/python2.7/site-packages/pip/download.py", line 892, in _download_http_url_download_url(resp, link, content_file, hashes)File "/usr/lib/python2.7/site-packages/pip/download.py", line 596, in _download_urlhashes.check_against_chunks(downloaded_chunks)File "/usr/lib/python2.7/site-packages/pip/utils/hashes.py", line 49, in check_against_chunksfor chunk in chunks:File "/usr/lib/python2.7/site-packages/pip/download.py", line 564, in written_chunksfor chunk in chunks:File "/usr/lib/python2.7/site-packages/pip/utils/ui.py", line 139, in iterfor x in it:File "/usr/lib/python2.7/site-packages/pip/download.py", line 553, in resp_readdecode_content=False):File "/usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 353, in streamdata = self.read(amt=amt, decode_content=decode_content)File "/usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 320, in readflush_decoder = TrueFile "/usr/lib64/python2.7/contextlib.py", line 35, in __exit__self.gen.throw(type, value, traceback)File "/usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 242, in _error_catcherraise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
You are using pip version 8.1.2, however version 24.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[root@yj test]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)

4 手动升级pip

最后,我去尝试手动升级pip,去手动下载pip的安装包。查询到需要去pip网站上根据上面的教程来下载。

网址:pip · PyPI

但这个时候,因为我的python只有2.7.5,第一感觉我不可能去下载最新版本的pip,于是我想去找python和pip版本的对应关系,但是没有找到,于是我试着去官网找老一点的版本的pip先尝试一下,我惊奇地发现,官方竟然只提供了最新版本地pip地安装脚本get-pip.py。虽然我可以点击老版本,进入对应地下载页面,但当我进入老版本地下载页面点击Installgration地时候,总会跳转到最新版本地下载页面。如下所示。

跳转到

于是我实在没有办法了,就试着下载这最新版本地pip脚本到我的linux服务器中执行。果不其然,报错了,显示最新版本的pip最低支持的python版本时3.8,我的python版本太低了,但是我没有注意后面的提示,我就去重新找了很多办法都没成功。

 偶然间,我看到了提示,我惊喜地点进去,果然那个脚本和最新版本地pip的安装脚本不一样,于是我赶紧操作进行最后的安装。

Please use https://bootstrap.pypa.io/pip/2.7/get-pip.py instead
[root@yj test]# python get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f9f749ab5d0>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /simple/pip/
Collecting pip<21.0WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f9f73d01490>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /packages/27/79/8a850fe3496446ff0d584327ae44e7500daf6764ca1a382d2d02789accf7/pip-20.3.4-py2.py3-none-any.whlWARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f9f73d01690>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /packages/27/79/8a850fe3496446ff0d584327ae44e7500daf6764ca1a382d2d02789accf7/pip-20.3.4-py2.py3-none-any.whlDownloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)|████████████████████████████████| 1.5 MB 193 kB/s 
Collecting wheelDownloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, wheelAttempting uninstall: pipFound existing installation: pip 8.1.2Uninstalling pip-8.1.2:Successfully uninstalled pip-8.1.2
Successfully installed pip-20.3.4 wheel-0.37.1
[root@yj test]# pip --version
pip 20.3.4 from /usr/lib/python2.7/site-packages/pip (python 2.7)

终于成功了,最后yaml模块也正常安装了,运行ansible --version也正确运行了。总算把这个问题给解决了!!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com