title: dotenv won't load in docker container
body: <p>I'm trying to run a python app in a docker container. The python app takes it's secrets from a <code>.env</code> file and uses <code>dotenv.load_dotenv</code> in python to pull the secrets in. Works absolutely fine when I run locally.. so I assumed it HAD to be to do with the version of Python running on the base image, however.. I've tried it with the exact same version as I'm running locally and it's still failing.</p>
  <p>Docker file:</p>
  <pre><code>FROM python:latest
  WORKDIR /casp
  COPY requirements.txt .
  RUN pip install -r requirements.txt
  COPY . /casp
  ENTRYPOINT [ &quot;python3&quot; ]
  CMD [ &quot;main.py&quot; ]
  </code></pre>
  <p>In my python app:</p>
  <pre><code>from pathlib import Path
  from dotenv import load_dotenv
  
  env_path = Path('.') / '.env'
  load_dotenv(dotenv_path=env_path)
  </code></pre>
  <p>I actually tried abandoning this idea completely, and reverting to passing the environment variables in using <code>docker run -e</code> but, it turns out <code>Flask</code> relies on <code>dot_env</code> also, and as such it fails there also.</p>
  <p>I've done a fair amount of looking already and it seems a lot of people do have Docker / Dotenv issues, but none seem to directly match this.</p>
  <p>Previous posts suggest it could be related to the location, but the path here is literally just <code>./env</code> which matches the container, since the <code>WORKDIR</code> is created then the entire app directory is copied into it, which includes <code>.env</code> and <code>main.py</code>.</p>
  <p>Error I'm seeing is:</p>
  <p><code>ImportError: cannot import name 'load_dotenv' from 'dotenv' (/usr/local/lib/python3.9/site-packages/dotenv/__init__.py)</code></p>
  <p>Current test is using <code>Python 3.9</code>. Locally I'm running <code>Python 3.85</code> - I have tried changing the <code>Dockerfile</code> to match this version... same error.</p>
  <p><strong>EDIT:</strong></p>
  <pre><code>(venv) root@jon-Blade:/home/jon/PycharmProjects/caspv2# pip freeze | grep dotenv
  python-dotenv==0.14.0
  (venv) root@jon-Blade:/home/jon/PycharmProjects/caspv2# grep dotenv requirements.txt 
  python-dotenv==0.14.0
  </code></pre>
  <p><strong>EDIT EDIT:</strong></p>
  <pre><code>root@jon-Blade:~# docker exec 2ce1ff67d74f pip list | grep dotenv
  python-dotenv  0.14.0
  </code></pre>
  <p><strong>EDIT EDIT EDIT:</strong></p>
  <p>From within the <em>container</em>:</p>
  <pre><code>&gt;&gt;&gt; import dotenv
  &gt;&gt;&gt; dir(dotenv)
  ['__author__', '__builtins__', '__cached__', '__doc__', '__email__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_get_line_', 'ast', 'get', 'load', 'os', 'save']
  </code></pre>
  <p>From within the venv in my <em>terminal</em>:</p>
  <pre><code>&gt;&gt;&gt; import dotenv
  &gt;&gt;&gt; dir(dotenv)
  ['IS_TYPE_CHECKING', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'compat', 'dotenv_values', 'find_dotenv', 'get_cli_string', 'get_key', 'load_dotenv', 'load_ipython_extension', 'main', 'parser', 'set_key', 'unset_key']
  </code></pre>
  <p>As we can see, in the container it's <code>load</code> and in the terminal it's <code>load_dotenv</code>. More importantly, it's different! Using the exact same version in <code>requirements.txt</code></p>
  <p><strong>Terminal:</strong></p>
  <pre><code>(venv) jon@jon-Blade:~/PycharmProjects/caspv2$ pip freeze | grep dotenv
  python-dotenv==0.14.0
  </code></pre>
  <p><strong>Container:</strong></p>
  <pre><code>root@2476f65ffa10:/casp# pip freeze | grep dotenv
  python-dotenv==0.14.0
  </code></pre>
  <p>Version from <strong>Terminal</strong>:</p>
  <pre><code>(venv) jon@jon-Blade:~/PycharmProjects/caspv2$ python --version
  Python 3.8.5
  </code></pre>
  <p>Version from <strong>Container</strong>:</p>
  <pre><code>root@3aa5c393846e:~# python --version
  Python 3.8.5
  </code></pre>
  <p>Running <code>pip show python-dotenv</code> on both also confirms the exact same details, line for line!</p>
  <p>This is certainly a fun one, it's confusing... but there has to be something funny going on.</p>
  <p><strong>EDIT EDIT EDIT EDIT :)</strong></p>
  <p>In the container I upgraded <code>python-dotenv</code> to <code>0.15.0</code>:</p>
  <pre><code>root@8a94c1e22b8a:~# pip show python-dotenv | grep -i version
  Version: 0.15.0
  </code></pre>
  <p>However:</p>
  <pre><code>&gt;&gt;&gt; import dotenv
  &gt;&gt;&gt; dir(dotenv)
  ['__author__', '__builtins__', '__cached__', '__doc__', '__email__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', '_get_line_', 'ast', 'get', 'load', 'os', 'save']
  </code></pre>
  <p>It's still giving me the wrong package.</p>