# Failed to import the required Python library (pexpect)

**URL:** <https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect/33618>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [August 14, 2020, 5:42pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect/33618 "2020-08-14T17:42:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nagesh\_sheregar](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nagesh\_sheregar](https://forum.ansible.com/u/Nagesh_sheregar)\
**Post date:** [August 14, 2020, 5:42pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect/33618/1 "2020-08-14T17:42:11Z")

</div>

Hi team,

i am getting below error, pexpect already installed

he full traceback is:  
Traceback (most recent call last):  
File “/tmp/ansible\_expect\_payload\_0bz7tQ/ **main**.py”, line 108, in   
import pexpect  
ImportError: No module named pexpect

fatal: [sddc\_mgr]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“chdir”: null,  
“command”: “sudo /opt/vmware/sddc-support/sos --health-check”,  
“creates”: null,  
“echo”: false,  
“removes”: null,  
“responses”: {  
“(?i)[sudo] password for vcf”: “xxxxxxxxxxxxxxxxxxxxx”  
},  
“timeout”: 30  
}  
},  
“msg”: “Failed to import the required Python library (pexpect) on [lab.local.com](http://lab.local.com)’s Python /usr/bin/python2.7. Please read module documentation and install in the appropriate location”

[root@6683ffa58609 cpc-vcf]# pip show pexpect  
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at [https://pip.pypa.io/en/latest/development/release-process/#python-2-support](https://pip.pypa.io/en/latest/development/release-process/#python-2-support)  
Name: pexpect  
Version: 4.8.0  
Summary: Pexpect allows easy control of interactive console applications.  
Home-page: [https://pexpect.readthedocs.io/](https://pexpect.readthedocs.io/)  
Author: Noah Spurrier; Thomas Kluyver; Jeff Quast  
Author-email: [noah@noah.org](mailto:noah@noah.org), [thomas@kluyver.me.uk](mailto:thomas@kluyver.me.uk), [contact@jeffquast.com](mailto:contact@jeffquast.com)  
License: ISC license  
Location: /usr/lib/python2.7/site-packages  
Requires: ptyprocess  
Required-by:  
[root@6683ffa58609 cpc-vcf]#

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 14, 2020, 5:53pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect/33618/2 "2020-08-14T17:53:04Z")

</div>

You forgot to post the playbook you’re using, and the inventory, and the ansible configuration.

---

<div class="post-metadata">

**Author:** ![Nagesh\_sheregar](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nagesh\_sheregar](https://forum.ansible.com/u/Nagesh_sheregar)\
**Post date:** [August 14, 2020, 5:57pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect/33618/3 "2020-08-14T17:57:29Z")

</div>

Oh sorry, please find the below details

host file

[root@6683ffa58609 cpc-vcf]# cat hosts.ini  
sddc\_mgr ansible\_user=vcf ansible\_password=‘xxxxxxxxxxxxxxxxxx’ ansible\_ssh\_host=10.47.20.4

[root@6683ffa58609 cpc-vcf]#

Playbook:

---

<div class="post-metadata">

**Author:** ![Nagesh\_sheregar](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nagesh\_sheregar](https://forum.ansible.com/u/Nagesh_sheregar)\
**Post date:** [August 14, 2020, 5:58pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect/33618/4 "2020-08-14T17:58:32Z")

</div>

Ansible version:

[root@6683ffa58609 cpc-vcf]# ansible --version  
ansible 2.8.4  
config file = /data01/ansible/cpc-vcf/ansible.cfg  
configured module search path = [u’/data01/ansible/cpc-vcf/library’, u’/data01/ansible/cpc-vcf/library/nsx’, u’/data01/ansible/cpc-vcf/library/vsphere’, u’/data01/ansible/cpc-vcf/library/vcenter’]  
ansible python module location = /usr/lib/python2.7/site-packages/ansible  
executable location = /usr/bin/ansible  
python version = 2.7.5 (default, Apr 2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]  
[root@6683ffa58609 cpc-vcf]#

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [August 14, 2020, 6:20pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect/33618/5 "2020-08-14T18:20:55Z")

</div>

Hi

It seems there is a lot of wheel reinventing going on by using expect/sudo to handle privilege escalation.  
Instead use the already existing privilege escalation options:

[https://docs.ansible.com/ansible/latest/user\_guide/become.html](https://docs.ansible.com/ansible/latest/user_guide/become.html)

---

<div class="post-metadata">

**Author:** ![Nagesh\_sheregar](https://avatars.discourse-cdn.com/v4/letter/n/3ec8ea/32.png) [@Nagesh\_sheregar](https://forum.ansible.com/u/Nagesh_sheregar)\
**Post date:** [August 14, 2020, 7:25pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect/33618/6 "2020-08-14T19:25:07Z")

</div>

Thank you, its worked:
