title: Cannot import name '_imaging' while trying to use Pillow inside AWS Lambda
body: <p>I am trying to make AWS Lambda function, which uses PIL. Hence I installed PIL inside my project directory with</p>
  
  <pre><code>pip install Pillow -t .
  </code></pre>
  
  <p>First time it ran on local machine, it caused </p>
  
  <pre><code>ImportError: cannot import name '_imaging'
  </code></pre>
  
  <p>I though I did something wrong and deleted <code>PIP</code> and <code>Pillow*</code> directories from project directory and reinstalled <code>PIL</code>. Then it worked. </p>
  
  <p>Unfortunately, when I packed everythong into ZIP and posted to AWS, the function started to fail with it again</p>
  
  <pre><code>Traceback (most recent call last):
    File "/var/task/myfile.py", line 9, in lambda_handler
      from PIL import Image
    File "/var/task/PIL/Image.py", line 64, in &lt;module&gt;
      from . import _imaging as core
  ImportError: cannot import name '_imaging'
  </code></pre>
  
  <p>What is the exact reason of this error and how fix it?</p>
  
  <p>Below are file list in my project dir:</p>
  
  <pre><code>$ ls
  bin                          chardet-3.0.4.dist-info  Pillow-5.2.0.dist-info     ThumbnailEnergent_Lambda.zip
  certifi                      idna                     requests                   myfile.py
  certifi-2018.4.16.dist-info  idna-2.7.dist-info       requests-2.19.1.dist-info  urllib3
  chardet                      PIL                      tests                      urllib3-1.23.dist-info
  </code></pre>