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

10 篇文章 0 订阅

经过上一篇文章,我虽然误删了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 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模块,但是又报错了。

pip install pyyaml
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年的。这个肯定太老了。

[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 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的安装脚本不一样,于是我赶紧操作进行最后的安装。

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.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也正确运行了。总算把这个问题给解决了!!

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Python安装Ansible,可以按照以下步骤进行操作: 1. 确保已经安装Pythonpip工具。Python版本应为2.7或更高版本。 2. 使用以下命令安装Ansible的依赖包: ``` pip install -U setuptools pycrypto cryptography ``` 3. 安装Ansible本身。可以使用以下命令安装最新版本的Ansible: ``` pip install ansible ``` 你也可以指定特定的版本进行安装,例如: ``` pip install ansible==2.9.9 ``` 在安装过程中,pip会自动下载并安装Ansible及其相关依赖包。 4. 安装完成后,可以使用以下命令检查Ansible的版本: ``` ansible --version ``` 这将显示已安装Ansible版本以及其他配置信息。 请注意,安装Ansible可能需要管理员权限。确保以管理员身份运行命令或在虚拟环境中进行安装。 引用提供了一个完整的安装Ansible的示例,其中包含更多细节和依赖项安装的步骤。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [python自动化之Ansible安装教程](https://download.csdn.net/download/weixin_38706951/13991839)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Linux-基于python2.7.5安装ansible最强攻略【适用于python3版本安装ansible】](https://blog.csdn.net/weixin_36522099/article/details/106595572)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值