title: No module named '_cffi_backend' when running python script using azure.storage.blob.BlockBlobService on Ubuntu in Docker
body: <p>I have a python3.6 script that needs to get content from a blob storage in Azure which I want to run in a Ubuntu 16.04 docker container.</p>
  <h1>The problem</h1>
  <p>I am using <a href="https://github.com/Microsoft/mssql-docker/blob/master/oss-drivers/pyodbc/Dockerfile" rel="nofollow noreferrer">this</a> dockerfile because I am also using pyodbc to connect to SQL Server. In my requirements file I have listed <code>azure.storage</code> which is installed when the docker image is built. But when trying to run the script I get the following error:</p>
  <pre><code>root@b61c65dadb5d:/app# python3 val.py
  Traceback (most recent call last):
    File &quot;val.py&quot;, line 12, in &lt;module&gt;
      from azure.storage.blob import BlockBlobService
    File &quot;/usr/local/lib/python3.6/dist-packages/azure/storage/__init__.py&quot;, line 21, in &lt;module&gt;
      from .models import (
    File &quot;/usr/local/lib/python3.6/dist-packages/azure/storage/models.py&quot;, line 27, in &lt;module&gt;
      from cryptography.hazmat.primitives.keywrap import(
    File &quot;/usr/local/lib/python3.6/dist-packages/cryptography/hazmat/primitives/keywrap.py&quot;, line 12, in &lt;module&gt;
      from cryptography.hazmat.primitives.constant_time import bytes_eq
    File &quot;/usr/local/lib/python3.6/dist-packages/cryptography/hazmat/primitives/constant_time.py&quot;, line 11, in &lt;module&gt;
      from cryptography.hazmat.bindings._constant_time import lib
  ImportError: No module named '_cffi_backend'
  </code></pre>
  <h1>What I have tried</h1>
  <p>I have found a couple suggestions after some searching, one of which suggested to run <code>pip install cffi</code>. When trying this I get:</p>
  <pre><code>root@b61c65dadb5d:/app# pip3 install cffi
  Requirement already satisfied: cffi in /usr/local/lib/python3.6/dist-packages (1.12.2)
  Requirement already satisfied: pycparser in /usr/local/lib/python3.6/dist-packages (from cffi) (2.19)
  </code></pre>
  <p>Same goes for <code>pip install cryptography</code></p>
  <p>Because python had trouble finding the azure module to begin with I have this at the beginning of my script, so it should be able to find anything located in that directory:</p>
  <pre><code>import sys
  
  sys.path.append('/usr/local/lib/python3.6/dist-packages')
  </code></pre>
  <p>(I know I can do this in the Dockerfile, and I will)</p>
  <p>Others say that adding <code>import cffi</code> in the python script solves the issue. It does not for me.</p>
  <h1>How to reproduce</h1>
  <p>This problem can easily be reproduced with this minimal python script:</p>
  <pre><code>import sys
  
  sys.path.append('/usr/local/lib/python3.6/dist-packages')
  
  from azure.storage.blob import BlockBlobService
  
  </code></pre>
  <p>Then build an image based on Ubuntu 16.04, installing python 3.6, and install azure.storage with pip. Dockerfile:</p>
  <pre><code>FROM ubuntu:16.04
  
  RUN apt-get update &amp;&amp; apt-get install -y apt-utils
  
  RUN apt-get install -y software-properties-common
  RUN add-apt-repository -y ppa:jonathonf/python-3.6
  RUN apt-get update &amp;&amp; apt-get install -y \
      python3.6 \
      python3.6-dev \
      python3-pip \
      python3-setuptools \
      python3-wheel \
      --no-install-recommends &amp;&amp; \
      python3.6 -m pip install --upgrade pip &amp;&amp; \
      rm -rf /var/lib/apt/lists/* &amp;&amp; \
      alias python=python3.6
  
  RUN pip3 install azure.storage
  
  COPY /app /app
  WORKDIR /app
  
  </code></pre>
  <p>Either run it interactively or add CMD for running the script. Note that the python script must be located in a folder named &quot;app&quot; in the same directory as the Dockerfile.</p>
  <p>If you are using interacive you can try <code>pip3 install cffi</code> to see that it's already installed.</p>
  <h1>Side note</h1>
  <p>I also want to mention that I have a similar problem when attempting to connect to a service bus on azure. But I will create another question for that spesific problem if I feel the need later.</p>