title: "Failed to import the required Python library (kubernetes)" despite the kubernetes module being installed
body: <p>I'm running Ansible on macOS 12.4 and I have following task which uses kubernetes.core.k8s module.</p>
  <pre><code>- name: &quot;apply {{ downloaded_metallb_manifest }}&quot;
    kubernetes.core.k8s:
      src: &quot;{{ downloaded_metallb_manifest }}&quot;
      state: present
      wait: yes
  </code></pre>
  <p>I installed the collection as per documentation - <a href="https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html" rel="nofollow noreferrer">https://docs.ansible.com/ansible/latest/collections/kubernetes/core/k8s_module.html</a></p>
  <pre><code>% ansible-galaxy collection install kubernetes.core               
  Starting galaxy collection install process
  Process install dependency map
  Starting collection install process
  Downloading https://galaxy.ansible.com/download/kubernetes-core-2.3.2.tar.gz to /Users/grit/.ansible/tmp/ansible-local-811952kgpja6g/tmpc_mrql42/kubernetes-core-2.3.2-c3aeycar
  Installing 'kubernetes.core:2.3.2' to '/Users/grit/.ansible/collections/ansible_collections/kubernetes/core'
  kubernetes.core:2.3.2 was installed successfully
  </code></pre>
  <p>However, the task still fails.</p>
  <pre><code>TASK [metallb : apply /tmp/metallb-native.yaml] ****************************************************************************************
  An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ModuleNotFoundError: No module named 'kubernetes'
  fatal: [node1.local]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;error&quot;: &quot;No module named 'kubernetes'&quot;, &quot;msg&quot;: &quot;Failed to import the required Python library (kubernetes) on node1's Python /usr/bin/python3. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter&quot;}
  </code></pre>
  <p>Running the playbook with explicit <code>-e 'ansible_python_interpreter=/usr/bin/python3'</code> doesn't make any difference.</p>
  <p>What went wrong here?</p>
  <p>Here is Ansible version.</p>
  <pre><code>ansible [core 2.13.1]
    config file = None
    configured module search path = ['/Users/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
    ansible python module location = /usr/local/Cellar/ansible/6.1.0/libexec/lib/python3.10/site-packages/ansible
    ansible collection location = /Users/user/.ansible/collections:/usr/share/ansible/collections
    executable location = /usr/local/bin/ansible
    python version = 3.10.5 (main, Jun 23 2022, 17:15:25) [Clang 13.1.6 (clang-1316.0.21.2.5)]
    jinja version = 3.1.2
    libyaml = True
  </code></pre>
  <p>The kubernetes collection is in the <code>ansible collection location</code></p>
  <pre><code>% ls -l /Users/user/.ansible/collections/ansible_collections 
  total 0
  drwxr-xr-x  3 user  staff  96 26 Aug 12:57 kubernetes
  drwxr-xr-x  3 user  staff  96 26 Aug 12:57 kubernetes.core-2.3.2.info
  </code></pre>
  <p>Following prerequisites have been installed as well.</p>
  <pre><code>% pip3 list | egrep -i 'kubernetes|pyyaml|jsonpatch'
  jsonpatch           1.32
  kubernetes          24.2.0
  PyYAML              6.0
  </code></pre>