簡體   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