ImportError when importing elasticsearch.helpers in Python
<p>I am using a docker container with <strong>Ubuntu 16.04 Xenial</strong> with a <strong>Python 3.5.2</strong> virtual environment. Every time I am trying to initialize the server uWSGI I am getting the following Python error:</p>

<pre><code>  File "/env/lib/python3.5/site-packages/elasticsearch_dsl/__init__.py", line 5, in &lt;module&gt;
    from .search import Search
  File "/env/lib/python3.5/site-packages/elasticsearch_dsl/search.py", line 3, in &lt;module&gt;
    from elasticsearch.helpers import scan
ImportError: No module named 'elasticsearch.helpers'
</code></pre>

<p>I have been running the bash manually inside the docker container to see what is wrong with the module. By running <code>pip list</code> in the virtual environment I can tell that the packages are correctly installed:</p>

<pre><code># pip list
elasticsearch (2.1.0)
elasticsearch-dsl (0.0.8)
</code></pre>

<p>Running <strong>sys.path</strong> shows that the site packages folder was correctly added to the python path:</p>

<pre class="lang-python prettyprint-override"><code>import sys
sys.path
[
  '', 
  '/env/lib/python35.zip', 
  '/env/lib/python3.5', 
  '/env/lib/python3.5/plat-x86_64-linux-gnu', 
  '/env/lib/python3.5/lib-dynload', 
  '/usr/lib/python3.5', 
  '/usr/lib/python3.5/plat-x86_64-linux-gnu', 
  '/env/lib/python3.5/site-packages'
]
</code></pre>

<p>There is a <strong>__init__.py</strong> file within the folder <strong>elasticsearch.helpers</strong> so that's not the problem. If I try the import from the Python console it will fail as well:</p>

<pre class="lang-python prettyprint-override"><code>from elasticsearch.helpers import scan
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ImportError: No module named 'elasticsearch.helpers'
</code></pre>

<p>But now if I go to the site-packages folder <code>cd /env/lib/python3.5/site-packages</code> and run python console from here, the import will work. </p>

<p>I don't really know why this is happening any help will be appreciated.</p>

<p>ouch... just a rookie mistake. One of the folders of my project was called elasticsearch and that was causing the issue.</p>

<p>Running the following command I found out that my app was simply loading the elasticsearch module from a different location. </p>

<pre class="lang-python prettyprint-override"><code>import elasticsearch
pprint.pprint(os.path.abspath(elasticsearch.__file__))
# /var/sites/my_app/elasticsearch/__init__.py
</code></pre>

python docker elasticsearch-py