首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用ansible和pip安装ansible

如何使用ansible和pip安装ansible
EN

Stack Overflow用户
提问于 2020-05-01 02:46:28
回答 1查看 1.1K关注 0票数 0

您好,我正在尝试用pip在ubuntu服务器Trusty64中使用vagrant和ansible来安装ansible。我使用角色来安装python3,在角色中安装ansible是:

代码语言:javascript
运行
复制
---
# tasks file for roles/ansible
- name: install pip3
  apt: name=python3-pip state=present
  tags: ansible

- name: install librerias dev
  apt: name=libssl-dev state=present
  tags: ansible

- name: install librerias essential
  apt: name=build-essential state=present
  tags: ansible

- name: install librerias libdev
  apt: name=libffi-dev state=present
  tags: ansible

- name: install librerias pydev
  apt: name=python-dev state=present
  tags: ansible

- name: install librerias pydev
  apt: upgrade=yes
  tags: ansible

- name: install setuptools
  command: pip3 install setuptools
  tags: ansible

- name: upgrade setuptools
  command: pip3 install --upgrade setuptools
  tags: ansible

- name: install ansible
  command: pip3 install ansible
  tags: ansible

在安装了python3和pip3之后,安装失败并返回下一个错误回溯:

代码语言:javascript
运行
复制
Python 3.5 or later is required",                                                                   
    "stderr_lines": [
        "Traceback (most recent call last):", 
        "  File \"/usr/bin/pip3\", line 5, in <module>", 
        "    from pkg_resources import load_entry_point", 
        "  File \"/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py\", line 93, in <module>", 
        "    raise RuntimeError(\"Python 3.5 or later is required\")", 
        "RuntimeError: Python 3.5 or later is required"
    ], 
    "stdout": "", 
    "stdout_lines": []
}

我不明白为什么我也要解决这个问题,因为我已经使用这个角色安装了python3:

代码语言:javascript
运行
复制
---
# tasks file for roles/python3

- name: aniadir repositorio
  apt_repository: 
   repo: ppa:deadsnakes/ppa
   state: present

- name: actualizar cache
  apt: update_cache=yes

- name: instalar python3
  apt: name=python3.7 state=present

我已经使用pip3安装了setuptools并对其进行了升级。我将非常感谢你的帮助。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-01 09:38:07

根据this answer的说法,你需要添加:

代码语言:javascript
运行
复制
- name: Select python3.7 as default python3
  alternatives:
    name: python3
    path: /usr/bin/python3.7

正如您在错误中看到的,Ansible尝试使用Python 3.4安装Ansible:

/usr/local/lib/python3.4/dist-packages/pkg_resources/__init__.py

Python 3.4是您安装的默认Python 3。安装Python3.7只会安装python3.7,但不会将其设置为默认的Python3。为此在调用 python3 时,您必须明确告诉系统使用 python3.7,使用alternatives system

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61530610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档