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

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

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

1 验证ansible时出错

bash 复制代码
yum install ansible
bash 复制代码
[root@yj test]# ansible --version
Traceback (most recent call last):
  File "/usr/bin/ansible", line 62, in <module>
    import ansible.constants as C
  File "/usr/lib/python2.7/site-packages/ansible/constants.py", line 19, in <module>
    from ansible.config.manager import ConfigManager, ensure_type, get_ini_config_value
  File "/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模块,但是又报错了。

bash 复制代码
pip install pyyaml
bash 复制代码
Collecting PyYAML
  Retrying (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) - skipping
  Could not find a version that satisfies the requirement PyYAML (from versions: )
No matching distribution found for PyYAML

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

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

3 命令升级pip时出错。

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

bash 复制代码
[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 pip
  Downloading 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 main
    status = self.run(options, args)
  File "/usr/lib/python2.7/site-packages/pip/commands/install.py", line 307, in run
    requirement_set.prepare_files(finder)
  File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 370, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/site-packages/pip/req/req_set.py", line 587, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/lib/python2.7/site-packages/pip/download.py", line 811, in unpack_url
    hashes=hashes
  File "/usr/lib/python2.7/site-packages/pip/download.py", line 650, in unpack_http_url
    hashes)
  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_url
    hashes.check_against_chunks(downloaded_chunks)
  File "/usr/lib/python2.7/site-packages/pip/utils/hashes.py", line 49, in check_against_chunks
    for chunk in chunks:
  File "/usr/lib/python2.7/site-packages/pip/download.py", line 564, in written_chunks
    for chunk in chunks:
  File "/usr/lib/python2.7/site-packages/pip/utils/ui.py", line 139, in iter
    for x in it:
  File "/usr/lib/python2.7/site-packages/pip/download.py", line 553, in resp_read
    decode_content=False):
  File "/usr/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/response.py", line 353, in stream
    data = 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 read
    flush_decoder = True
  File "/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_catcher
    raise 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的安装脚本不一样,于是我赶紧操作进行最后的安装。

bash 复制代码
Please use https://bootstrap.pypa.io/pip/2.7/get-pip.py instead
bash 复制代码
[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.0
  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 0x7f9f73d01490>: Failed to establish a new connection: [Errno 101] Network is unreachable',)': /packages/27/79/8a850fe3496446ff0d584327ae44e7500daf6764ca1a382d2d02789accf7/pip-20.3.4-py2.py3-none-any.whl
  WARNING: 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.whl
  Downloading pip-20.3.4-py2.py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 193 kB/s 
Collecting wheel
  Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: pip, wheel
  Attempting uninstall: pip
    Found existing installation: pip 8.1.2
    Uninstalling 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也正确运行了。总算把这个问题给解决了!!

相关推荐
Ven%2 小时前
如何修改pip全局缓存位置和全局安装包存放路径
人工智能·python·深度学习·缓存·自然语言处理·pip
Linux运维技术栈1 天前
Ansible(自动化运维)环境搭建及ansible-vault加密配置
运维·自动化·ansible
花晓木1 天前
ansible安装文档
ansible
vvw&1 天前
如何在 Ubuntu 22.04 上安装 Ansible 教程
linux·运维·服务器·ubuntu·开源·ansible·devops
Kiros_Jiang2 天前
开源低代码平台-Microi吾码 打印引擎使用
javascript·开源·json·.net·pip
☆凡尘清心☆2 天前
CentOS-stream-9安装ansible
linux·centos·ansible
墨水\\2 天前
Ansible---playbook剧本
ansible
墨水\\3 天前
Ansible部署及基础模块
服务器·网络·ansible
七七powerful3 天前
ansible play-book玩法
linux·服务器·ansible
西格玛懒大王4 天前
[python] 基于matplotlib实现雷达图的绘制
数据库·python·pycharm·pip