# Import Error with custom Python module

**URL:** <https://forum.ansible.com/t/import-error-with-custom-python-module/14882>\
**Category:** Ansible Project\
**Created:** [March 28, 2014, 11:53am UTC](https://forum.ansible.com/t/import-error-with-custom-python-module/14882 "2014-03-28T11:53:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Edelman](https://avatars.discourse-cdn.com/v4/letter/j/c37758/32.png) [@Jason\_Edelman](https://forum.ansible.com/u/Jason_Edelman)\
**Post date:** [March 28, 2014, 11:53am UTC](https://forum.ansible.com/t/import-error-with-custom-python-module/14882/1 "2014-03-28T11:53:43Z")

</div>

Hi All,

I keep getting an “ImportError: No module named” when I try and run a playbook using a custom python module (that is trying to import a 3rd party python package).

Few things:

- importing the 3rd party package works from the python shell from all over my machine.
- PYTHONPATH seems to be correct, hence, importing the package works
- using the hacking test script also does NOT reproduce the error. So this works fine.
- I’ve tried ansible\_python\_interpreter=/usr/bin/python2.7
- Seem to have removed py3 just by using rm
- using ‘connection: local’ so the target host is “my host” also executing the playbook

I’m a new guy, so help me not leave any stone unturned :). Don’t assume anything please!

Thanks in advance.

-Jason

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [March 31, 2014, 8:38pm UTC](https://forum.ansible.com/t/import-error-with-custom-python-module/14882/2 "2014-03-31T20:38:05Z")

</div>

What is the path to your module? Also, have you checked out [http://docs.ansible.com/developing\_modules.html](http://docs.ansible.com/developing_modules.html) to see that your following our instructions for custom module development?

---

<div class="post-metadata">

**Author:** ![Jason\_Edelman](https://avatars.discourse-cdn.com/v4/letter/j/c37758/32.png) [@Jason\_Edelman](https://forum.ansible.com/u/Jason_Edelman)\
**Post date:** [April 1, 2014, 12:21pm UTC](https://forum.ansible.com/t/import-error-with-custom-python-module/14882/3 "2014-04-01T12:21:20Z")

</div>

Okay, so my error was very very stupid. Everything was correct, but I was executing the playbook as such ‘sudo ansible-playbook xxxxx’ and believe since was sudo’ing, I was losing the environment variables that were previously set. Either way, after running it without sudo, it worked just fine.
