繁体   English   中英

zsh:找不到命令:pip 安装后的 ansible

[英]zsh: command not found: ansible after pip installing

I've installed ansible on my Mac using pip as advised by ansible's documentation: 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"

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

After installing ansible with python3 -m pip install --user ansible , I searched for the ansible binary and found it to be downloaded into ~/Library/Python/3.8/bin . 最简单的方法是解决这个问题:

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

从那里开始,它很容易,只需更新 your.bash_profile 或 .zshrc

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

你应该对 go 很好:

$ 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']

brew install ansible
brew link ansible

卸载 ansible sudo pip uninstall ansible
然后使用 pip3 sudo pip3 install ansible
使用ansible --version检查版本。

ansible 2.10.3

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

以下命令对我有用:

卸载 ansible

须藤 pip 卸载 ansible

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

sudo -H pip3 安装 ansible

通过使用检查版本

ansible --version

我有多个 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

我看到了同样的错误,我错过了 ansible-lint

brew install ansible
brew install ansible-lint

安装后像:

python3 -m pip install --user ansible

编辑.zshrc:

export PATH=$HOME/bin:/usr/local/bin:$HOME/.local/bin:$PATH

你应该添加$HOME/.local/bin

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM