【问题标题】:zsh: command not found: ansible after pip installingzsh:找不到命令:pip安装后ansible
【发布时间】:2022-02-03 02:08:50
【问题描述】:

按照 ansible 的文档的建议,我使用 pip 在我的 Mac 上安装了 ansible: https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#installing-ansible-on-macos

但是,当我尝试运行 ansible 时,我得到以下信息: zsh: command not found: ansible

我之前在安装 ansible 时从来没有遇到过这个问题。

pip-installing 再次告诉我它已经安装在站点包下: Requirement already satisfied: ansible in ./Library/Python/3.8/lib/python/site-packages (2.9.11)

我在 ~/.zshrc 中的 python 安装指向:

# Add user python 3.7 to path
export PATH="/usr/local/opt/python/libexec/bin:$PATH"

对某些人来说可能很明显,但我不明白为什么这个简单的安装不起作用..

【问题讨论】:

  • 您使用哪个命令安装 Ansible? pip install --user ansible? sudo pip install ansible?
  • 我使用推荐的pip install --user ansible安装
  • 你可能想检查$HOME/Library/Python/3.8/bin,看看它是否在那里写了shell脚本;在这种情况下,我无法根据输出判断. 代表什么;你可能还想试试pip uninstall -y ansible && pip install --user -v -v -v ansible,看看它到底做了什么
  • @mdaniel 谢谢 - ansible 确实存在于那个 Python/3.8/bin 文件夹中,所以我刚刚在我的 .zshrc 文件中为它创建了一个别名。我以前不必这样做。像这样进行 ansible 设置有什么缺点吗?
  • 不是我知道的,虽然如果 /usr/local/opt/python/libexec/bin 是因为 python 是通过 Homebrew 安装的,你知道你可以 brew install ansible 然后把 /usr/local/bin 放在你的 PATH 中吗?

标签: macos ansible


【解决方案1】:

python3 -m pip install --user ansible安装ansible后,我搜索了ansible二进制文件,发现下载到~/Library/Python/3.8/bin。最简单的方法是解决这个问题:

$ cd ~
$ find . | grep ansible
<lines omitted>
./Library/Python/3.8/bin/ansible
<lines omitted>

从那里开始,非常简单,只需更新您的 .bash_profile 或 .zshrc 即可

export PATH="/path/to/Library/Python/3.8/bin:$PATH"

你应该很高兴:

$ source ~/.zshrc
$ ansible --version
ansible 2.10.8
  config file = None
  configured module search path = ['/Users/dbove/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

【讨论】:

    【解决方案2】:

    brew install ansible
    brew link ansible

    【讨论】:

    • 当我使用 pip3 安装 ansible 时,我一遍又一遍地遇到同样的问题。最后, brew install ansible 成功了。
    • 这可能不是问题的直接答案,但它确实解决了根本问题。使用 pip 安装对我不起作用,尽管使用 --user 或作为 sudo。用 brew 一口气一切都很好。 brew install ansible 就够了。不需要链接。
    • 我应该添加:首先卸载 ansible:python -m pip uninstall ansible 然后运行 ​​brew install ansible,然后运行 ​​brew link ansible。最好的方法
    【解决方案3】:

    以下命令对我有用:

    卸载ansible

    sudo pip 卸载 ansible

    然后使用安装(注意:-H 标志在这里很重要,它将 HOME 变量设置为目标用户的主目录)

    sudo -H pip3 install ansible

    使用检查版本

    ansible --version

    【讨论】:

      【解决方案4】:

      卸载 ansible sudo pip uninstall ansible.
      然后使用 pip3 sudo pip3 install ansible安装。
      使用ansible --version查看版本。

      ansible 2.10.3

      注意:确保您已安装 pip3,如果您没有安装,请使用 brew install python3

      【讨论】:

      • 我完全按照你说的做了,但我还是得到了zsh: command not found: ansible
      • 使用下面这个对我有用的命令。甚至我以前也面临过类似的问题。 > sudo -H pip3 install ansible
      • @crg 你必须先用其他东西安装过ansible,用那个安装程序卸载它,然后按照步骤操作。例如,您之前可能使用 apt-get 安装了 ansible,因此请使用 apt-get 或您之前使用过的任何工具卸载它。
      • 我终于做到了brew ansible 现在它可以工作了,谢谢
      • 使用 Homebrew 安装的完整命令是 brew install ansible
      【解决方案5】:

      我有多个 ansible 实例。我按照以下步骤纠正了 ansible command not found 错误。

      1. 卸载旧的 /所有 ansible 实例
      python3 -m pip uninstall ansible
      python3 -m pip uninstall ansible-core
      
      1. 查找所有 ansible 实例
      cd ~
      find . | grep ansible
      
      1. 从第 2 步中删除所有目录
      rm -rf /usr/local/lib/python3.6/site-packages/ansible*
      rm -rf /root/.local/lib/python3.6/site-packages/ansible
      rm -rf ./.ansible
      rm -rf ./.local/lib/python3.6/site-packages/ansible_test
      
      1. 再次安装 ansible
      sudo yum install python3-pip 
      pip3 install ansible
      pip3 install openshift
      
      1. 验证
      pip3 list  | grep ansible
      ansible (4.8.0)
      ansible-core (2.11.6)
      
      ansible --version
      [DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.8 (default, Sep 12 2021, 04:40:35) [GCC 
      8.4.1 20200928 (Red Hat 8.4.1-1)]. This feature will be removed from ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False 
      in ansible.cfg.
      ansible [core 2.11.6] 
        config file = None
        configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
        ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
        ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
        executable location = /usr/local/bin/ansible
        python version = 3.6.8 (default, Sep 12 2021, 04:40:35) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
        jinja version = 3.0.2
        libyaml = True
      

      【讨论】:

        【解决方案6】:

        我看到同样的错误,我缺少 ansible-lint

        brew install ansible
        brew install ansible-lint
        

        【讨论】:

          猜你喜欢
          • 2015-10-15
          • 1970-01-01
          • 2017-08-09
          • 1970-01-01
          • 2012-09-26
          • 2016-11-05
          • 1970-01-01
          • 2018-02-07
          • 1970-01-01
          相关资源
          最近更新 更多