# Failed to import the required Python library (pexpect) on sejenk01's Python /usr/bin/python.

**URL:** <https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect-on-sejenk01s-python-usr-bin-python/34212>\
**Category:** Ansible Project\
**Created:** [November 19, 2020, 8:04pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect-on-sejenk01s-python-usr-bin-python/34212 "2020-11-19T20:04:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prathap\_Dasari](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@Prathap\_Dasari](https://forum.ansible.com/u/Prathap_Dasari)\
**Post date:** [November 19, 2020, 8:04pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect-on-sejenk01s-python-usr-bin-python/34212/1 "2020-11-19T20:04:20Z")

</div>

SUMMARY

We are getting below errors if using the except module in the ansible playbooks.  
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named ptyprocess fatal: [sejenk01]: FAILED! =\> {“changed”: false, “msg”: “Failed to import the required Python library (pexpect) on sejenk01’s Python /usr/bin/python. Please read module documentation and install 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”}

PLAYBOOK:- name: Creating a OSB domain  
expect:  
command: “{{ wldt\_home }}/weblogic-deploy/bin/createDomain.sh -run\_rcu -oracle\_home {{ oracle\_home }} -domain\_parent {{ domainParentDir }} -domain\_type OSB -model\_file {{ oracle\_jinja\_templates }}/OsbDomainModel.yaml -rcu\_db {{ connection\_string }} -rcu\_prefix {{ schema\_prefix }} -rcu\_db\_user {{ db\_user }}”  
responses:  
‘Enter the RCU database SYS user password’: “{{ db\_password }}”  
‘Please enter the RCU Schema password’: “{{ schema\_password }}”  
timeout: 1200  
ISSUE TYPE- Bug Report  
COMPONENT NAME

ansible

ANSIBLE VERSION

ansible 2.9.10  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/Users/prathapdasari/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /Library/Python/2.7/site-packages/ansible  
executable location = /usr/local/bin/ansible  
python version = 2.7.16 (default, Jun 5 2020, 22:59:21) [GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc-  
PrathapDasaris-MacBook-Pro:ansible-wdt prathapdasari$

python --version  
Python 2.7.5

OS / ENVIRONMENT

Linux sefmw01 4.1.12-124.39.5.1.el7uek.x86\_64 [#2](https://github.com/ansible/ansible/issues/2) SMP Tue Jun 9 20:03:37 PDT 2020 x86\_64 x86\_64 x86\_64 GNU/Linux

EXPECTED RESULTS

it should be completed on remote servers without any errors.

---

<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:** [November 19, 2020, 10:45pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect-on-sejenk01s-python-usr-bin-python/34212/2 "2020-11-19T22:45:17Z")

</div>

Hi

> SUMMARY
> 
> We are getting below errors if using the except module in the ansible playbooks.

Did you actually read the error? It says exactly what is wrong, with  
hints on how to fix it:

---

<div class="post-metadata">

**Author:** ![Prathap\_Dasari](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@Prathap\_Dasari](https://forum.ansible.com/u/Prathap_Dasari)\
**Post date:** [November 19, 2020, 11:09pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect-on-sejenk01s-python-usr-bin-python/34212/3 "2020-11-19T23:09:28Z")

</div>

Hi,

The package already installed on the remote host but still, it´s failing with the above error.  
[root@sejenk01 ~]# yum install pexpect  
Loaded plugins: ulninfo  
Package pexpect-2.3-11.el7.noarch already installed and latest version  
Nothing to do

Regards,  
Prathap

---

<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:** [November 19, 2020, 11:19pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect-on-sejenk01s-python-usr-bin-python/34212/4 "2020-11-19T23:19:11Z")

</div>

Ansible needs the python pexpect package.

---

<div class="post-metadata">

**Author:** ![Prathap\_Dasari](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@Prathap\_Dasari](https://forum.ansible.com/u/Prathap_Dasari)\
**Post date:** [November 19, 2020, 11:36pm UTC](https://forum.ansible.com/t/failed-to-import-the-required-python-library-pexpect-on-sejenk01s-python-usr-bin-python/34212/5 "2020-11-19T23:36:08Z")

</div>

Ok. Apologies for this because I am new to scripting and doing the first time so little confused.

Now I need to install python packages on my remote hots right ?. If yes, can I follow the below steps to install python packages?

```auto
mv pexpect-4.2.1.tar.gz /usr/local/src/
cd /usr/local/src
tar zxvf pexpect-4.2.1.tar.gz
cd pexpect-4.2.1
python setup.py install

```

```auto

```

```auto
Regards,

```

```auto
Prathap

```
