title: Alpine Linux : package installed but module not found
body: <p>I'm building a <code>docker</code> image for a data science project.</p>
  
  <p>I install core dependencies via <code>RUN apk add &lt;package&gt;</code>.</p>
  
  <p><strong>Dockerfile-dev</strong></p>
  
  <pre><code>FROM python:3.6-alpine
  
  #SOFTWARE PACKAGES
  ENV PACKAGES="\
      dumb-init \
      musl \
      libc6-compat \
      linux-headers \
      build-base \
      bash \
      git \
      ca-certificates \
      freetype \
      libgfortran \
      libgcc \
      libstdc++ \
      openblas \
      tcl \
      tk \
      libssl1.0 \
      "
  # PYTHON DATA SCIENCE PACKAGES    
  ENV PYTHON_PACKAGES="\
      numpy \
      matplotlib \
      scipy \
      scikit-learn \
      pandas \
      nltk \
      "     
  RUN apk add --no-cache --virtual build-dependencies python3 \
      &amp;&amp; apk add --virtual build-runtime \
      build-base python3-dev openblas-dev freetype-dev pkgconfig gfortran \
      &amp;&amp; ln -s /usr/include/locale.h /usr/include/xlocale.h \
      &amp;&amp; python3 -m ensurepip \
      &amp;&amp; rm -r /usr/lib/python*/ensurepip \
      &amp;&amp; pip3 install --upgrade pip setuptools \
      &amp;&amp; ln -sf /usr/bin/python3 /usr/bin/python \
      &amp;&amp; ln -sf pip3 /usr/bin/pip \
      &amp;&amp; rm -r /root/.cache \
      &amp;&amp; pip install --no-cache-dir $PYTHON_PACKAGES \
      &amp;&amp; apk del build-runtime \
      &amp;&amp; apk add --no-cache --virtual build-dependencies $PACKAGES \
      &amp;&amp; rm -rf /var/cache/apk/*
  
  # add and install requirements
  COPY ./requirements.txt /usr/src/app/requirements.txt
  RUN pip install -r requirements.txt
  </code></pre>
  
  <p>Everything was build up to <code>pandas</code>, at which point this error appeared:</p>
  
  <pre><code>    Complete output from command python setup.py egg_info:
      Traceback (most recent call last):
        File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 359, in get_provider
          module = sys.modules[moduleOrReq]
      KeyError: 'numpy'
  
      During handling of the above exception, another exception occurred:
  
      Traceback (most recent call last):
        File "&lt;string&gt;", line 1, in &lt;module&gt;
        File "/tmp/pip-install-v7gyw8y_/pandas/setup.py", line 732, in &lt;module&gt;
          ext_modules=maybe_cythonize(extensions, compiler_directives=directives),
        File "/tmp/pip-install-v7gyw8y_/pandas/setup.py", line 475, in maybe_cythonize
          numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')
        File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1144, in resource_filename
          return get_provider(package_or_requirement).get_resource_filename(
        File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 361, in get_provider
          __import__(moduleOrReq)
      ModuleNotFoundError: No module named 'numpy'
  
      ----------------------------------------
  Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-v7gyw8y_/pandas/
  </code></pre>
  
  <p>But <code>numpy</code> HAD been installed beforehand:</p>
  
  <blockquote>
    <p>Running setup.py install for numpy: finished with status 'done'</p>
  </blockquote>
  
  <p>Not yet defeated, I moved <code>pandas==0.20.3</code> (this version worked in my conda <code>py36</code> env) into <code>requirements.txt</code>, and it was installed, as log reveals:</p>
  
  <pre><code>Successfully built: pandas
  Installing collected packages: pandas
  Successfully installed: pandas-0.20.3
  </code></pre>
  
  <p>After build time, however, running the container logs the following error:</p>
  
  <pre><code>users_1     | File "/usr/src/app/project/api/classifiers/metadata/learn.py", line 14, in &lt;module&gt;
  users_1     |     import pandas as pd
  users_1     | ModuleNotFoundError: No module named 'pandas'
  </code></pre>
  
  <p><strong>So it was installed by <code>pip</code> but can't be found?</strong></p>
  
  <p>How do install <code>pandas</code> via <code>RUN apk add</code> in order to keep build consistency for my data science project?</p>