# ImportError: No module named requests

**URL:** <https://forum.ansible.com/t/importerror-no-module-named-requests/33428>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [July 17, 2020, 11:16pm UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428 "2020-07-17T23:16:12Z")\
**Posts on this page:** 9\
**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:** [July 17, 2020, 11:16pm UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/1 "2020-07-17T23:16:12Z")

</div>

Hi team,

can someone please help me on this

TASK [vcenter : Gather all registered virtual machines] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /data01/ansible/playbooks/roles/vcenter/tasks/vminfo.yml:1  
 ESTABLISH LOCAL CONNECTION FOR USER: root  
 EXEC /bin/sh -c ‘echo ~root && sleep 0’  
 EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /root/.ansible/tmp`”&& mkdir /root/.ansible/tmp/ansible-tmp-1595027452.91-724-178923688175376 && echo ansible-tmp-1595027452.91-724-178923688175376=“`echo /root/.ansible/tmp/ansible-tmp-1595027452.91-724-178923688175376`” ) && sleep 0’  
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/vmware/vmware\_vm\_info.py  
 PUT /root/.ansible/tmp/ansible-local-583pCESFN/tmpfbE3DT TO /root/.ansible/tmp/ansible-tmp-1595027452.91-724-178923688175376/AnsiballZ\_vmware\_vm\_info.py  
 EXEC /bin/sh -c ‘chmod u+x /root/.ansible/tmp/ansible-tmp-1595027452.91-724-178923688175376/ /root/.ansible/tmp/ansible-tmp-1595027452.91-724-178923688175376/AnsiballZ\_vmware\_vm\_info.py && sleep 0’  
 EXEC /bin/sh -c ‘/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1595027452.91-724-178923688175376/AnsiballZ\_vmware\_vm\_info.py && sleep 0’  
 EXEC /bin/sh -c ‘rm -f -r /root/.ansible/tmp/ansible-tmp-1595027452.91-724-178923688175376/ \> /dev/null 2\>&1 && sleep 0’  
The full traceback is:  
Traceback (most recent call last):  
File “/tmp/ansible\_vmware\_vm\_info\_payload\_pV6E6R/ansible\_vmware\_vm\_info\_payload.zip/ansible/module\_utils/vmware.py”, line 24, in   
import requests  
ImportError: No module named requests  
fatal: [localhost → localhost]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“folder”: null,  
“hostname”: “10.10.10.18”,  
“password”: “VALUE\_SPECIFIED\_IN\_NO\_LOG\_PARAMETER”,  
“port”: 443,  
“proxy\_host”: null,  
“proxy\_port”: null,  
“show\_attribute”: false,  
“show\_tag”: false,  
“username”: “root”,  
“validate\_certs”: false,  
“vm\_type”: “all”  
}  
},  
“msg”: “Failed to import the required Python library (requests) on s605141sl7vl402.savvis.lab’s Python /usr/bin/python2. 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”  
}

[root@s605141sl7vl402 ansible]# ansible --version  
ansible 2.9.9  
config file = /etc/ansible/ansible.cfg  
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python2.7/site-packages/ansible  
executable location = /usr/bin/ansible  
python version = 2.7.17 (default, Nov 15 2019, 19:24:58) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]  
[root@s605141sl7vl402 ansible]#

Package Version

* * *

certifi 2020.6.20  
chardet 3.0.4  
idna 2.10  
pip 20.1.1  
pyvmomi 7.0  
requests 2.24.0  
setuptools 0.9.8  
six 1.15.0  
urllib3 1.25.9

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 18, 2020, 1:17am UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/2 "2020-07-18T01:17:45Z")

</div>

On s605141sl7vl402.savvis.lab, do

pip install requests

---

<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:** [July 18, 2020, 1:37am UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/3 "2020-07-18T01:37:50Z")

</div>

Hi abhi,

itsy already there:

[root@s605141sl7vl402 ansible]# pip list | grep requests  
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)  
requests 2.24.0  
[root@s605141sl7vl402 ansible]#

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 18, 2020, 2:42am UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/4 "2020-07-18T02:42:58Z")

</div>

can you check

pip show requests

---

<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:** [July 18, 2020, 2:46am UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/5 "2020-07-18T02:46:15Z")

</div>

Hi abhi,

Name: requests  
Version: 2.24.0  
Summary: Python HTTP for Humans.  
Home-page: [https://requests.readthedocs.io](https://requests.readthedocs.io)  
Author: Kenneth Reitz  
Author-email: [me@kennethreitz.org](mailto:me@kennethreitz.org)  
License: Apache 2.0  
Location: /opt/rh/python27/root/usr/lib/python2.7/site-packages  
Requires: certifi, idna, chardet, urllib3  
Required-by: pyvmomi

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 18, 2020, 3:06am UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/6 "2020-07-18T03:06:42Z")

</div>

Ansible is using /usr/bin/python2 and requests is installed in /opt/rh/python27/root/usr/lib/python2.7/site-packages

Set ansible\_python\_interpreter as in the playbook or adjust your python path -

vars:  
ansible\_python\_interpreter: ‘/opt/rh/python27/root/usr/lib/python2.7/bin/python’  
tasks:

Read more about Python Interpreter = [https://docs.ansible.com/ansible/latest/reference\_appendices/python\_3\_support.html](https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html) and [https://docs.ansible.com/ansible/latest/reference\_appendices/interpreter\_discovery.html#interpreter-discovery](https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html#interpreter-discovery)

---

<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:** [July 19, 2020, 7:56pm UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/7 "2020-07-19T19:56:17Z")

</div>

Hi Abhijith,

i am getting error like below:

ASK [vcenter : Gather all registered virtual machines] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
task path: /data01/ansible/playbooks/roles/vcenter/tasks/vminfo.yml:1  
 ESTABLISH LOCAL CONNECTION FOR USER: root  
 EXEC /bin/sh -c ‘echo ~root && sleep 0’  
 EXEC /bin/sh -c ‘( umask 77 && mkdir -p “`echo /root/.ansible/tmp`”&& mkdir /root/.ansible/tmp/ansible-tmp-1595188451.63-5049-188421523167796 && echo ansible-tmp-1595188451.63-5049-188421523167796=“`echo /root/.ansible/tmp/ansible-tmp-1595188451.63-5049-188421523167796`” ) && sleep 0’  
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/vmware/vmware\_vm\_info.py  
 PUT /root/.ansible/tmp/ansible-local-4928PgdUse/tmp7ZHjvD TO /root/.ansible/tmp/ansible-tmp-1595188451.63-5049-188421523167796/AnsiballZ\_vmware\_vm\_info.py  
 EXEC /bin/sh -c ‘chmod u+x /root/.ansible/tmp/ansible-tmp-1595188451.63-5049-188421523167796/ /root/.ansible/tmp/ansible-tmp-1595188451.63-5049-188421523167796/AnsiballZ\_vmware\_vm\_info.py && sleep 0’  
 EXEC /bin/sh -c ‘/opt/rh/python27/root/usr/lib/python2.7/site-packages /root/.ansible/tmp/ansible-tmp-1595188451.63-5049-188421523167796/AnsiballZ\_vmware\_vm\_info.py && sleep 0’  
 EXEC /bin/sh -c ‘rm -f -r /root/.ansible/tmp/ansible-tmp-1595188451.63-5049-188421523167796/ \> /dev/null 2\>&1 && sleep 0’  
fatal: [localhost → localhost]: FAILED! =\> {  
“changed”: false,  
“module\_stderr”: “/bin/sh: /opt/rh/python27/root/usr/lib/python2.7/site-packages: Is a directory\n”,  
“module\_stdout”: “”,  
“msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,  
“rc”: 126  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=3 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

[root@s605141sl7vl402 ansible]#

below is the my playbook:

- name: Gather all registered virtual machines  
vmware\_vm\_info:  
hostname: ‘{{ vcenter\_server }}’  
username: ‘{{ vcenter\_user }}’  
password: ‘{{ vcenter\_pass }}’  
validate\_certs: no  
delegate\_to: localhost  
register: vminfo  
vars:  
ansible\_python\_interpreter: ‘/opt/rh/python27/root/usr/lib/python2.7/site-packages’

---

<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:** [July 19, 2020, 8:43pm UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/8 "2020-07-19T20:43:20Z")

</div>

Yes you get an error because you didn’t try the suggestion provided by Abhijith. Instead you used a directory as the python interpreter. That is not going to work - as the error says.

Try Abhijit’s suggestion.

---

<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:** [July 19, 2020, 8:52pm UTC](https://forum.ansible.com/t/importerror-no-module-named-requests/33428/9 "2020-07-19T20:52:32Z")

</div>

got it, its worked now, Thank you
