title: Flask app imports fail when launched under uWsgi
body: <p>First, let me point out that this works fine using <code>flask run</code>. Also note the behavior is identical on Ubuntu 16.04 and macOS 10.12.4. I'm using a Python 3.6.0 virtualenv on macOS and 3.5.2 on Ubuntu.</p>
  
  <p>I have the following Flask app structure:</p>
  
  <pre><code>tsint/
      __init__.py
      app.py
      wsgi.py
      ...
  </code></pre>
  
  <p><code>__init__.py</code>:</p>
  
  <pre><code>from flask import Flask
  
  gApp = Flask(__name__)
  
  #   Config
  
  gApp.config.from_envvar('TSINT_CONFIG')
  
  #
  # DB
  #
  
  gDB = SQLAlchemy(gApp)
  
  #
  #   Import the views.
  #
  
  import tsint.app
  import tsint.admin
  </code></pre>
  
  <p><code>app.py</code> is the main Flask routes and such, and defines the Flask user
  datastore and security.</p>
  
  <p><code>wsgi.py</code>:</p>
  
  <pre><code>from tsint import gApp
  
  if __name__ == "__main__":
      gApp.run()
  </code></pre>
  
  <p>When I try testing <code>wsgi</code>, I get this “No module named 'flask'”:</p>
  
  <pre><code>$ cd &lt;directory containing tsint above&gt;
  $ uwsgi --socket 0.0.0.0:5000 --protocol=http -w tsint
  *** Starting uWSGI 2.0.14 (64bit) on [Wed May 10 19:57:59 2017] ***
  compiled with version: 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1) on 15 March 2017 15:31:30
  os: Darwin-16.5.0 Darwin Kernel Version 16.5.0: Fri Mar  3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64
  nodename: EclipseSSD.local
  machine: x86_64
  clock source: unix
  pcre jit disabled
  detected number of CPU cores: 8
  current working directory: /Users/rmann/Projects/Fiber/SignupApp
  detected binary path: /Users/rmann/Projects/Fiber/SignupApp/venv/bin/uwsgi
  *** WARNING: you are running uWSGI without its master process manager ***
  your processes number limit is 709
  your memory page size is 4096 bytes
  detected max file descriptor number: 1024
  lock engine: OSX spinlocks
  thunder lock: disabled (you can enable it with --thunder-lock)
  uwsgi socket 0 bound to TCP address 0.0.0.0:5000 fd 3
  Python version: 3.6.0 (default, Mar  9 2017, 14:47:47)  [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]
  *** Python threads support is disabled. You can enable it with --enable-threads ***
  Python main interpreter initialized at 0x7fe77e000000
  your server socket listen backlog is limited to 100 connections
  your mercy for graceful operations on workers is 60 seconds
  mapped 72752 bytes (71 KB) for 1 cores
  *** Operational MODE: single process ***
  Traceback (most recent call last):
    File "./tsint/__init__.py", line 1, in &lt;module&gt;
      from flask import Flask
  ModuleNotFoundError: No module named 'flask'
  unable to load app 0 (mountpoint='') (callable not found or import error)
  *** no app loaded. going in full dynamic mode ***
  *** uWSGI is running in multiple interpreter mode ***
  spawned uWSGI worker 1 (and the only) (pid: 26305, cores: 1)
  </code></pre>
  
  <p>I'm running in a virtualenv, which contains all the modules. I'm guessing <code>wsgi</code>
  isn't aware of those? I'm not clear on what I'm missing.</p>
  
  <h2>EDIT:</h2>
  
  <p>I've changed things up a bit to match the various tutorials a bit better, but
  the result is unchanged.</p>
  
  <p>My directory structure now looks like this:</p>
  
  <pre><code>tsint/
      requirements.txt
      setup.py
      wsgi.py
      env/
      tsint/
          __init__.py
          app.py
          static/
          templates/
          ...
  </code></pre>
  
  <p>Again, when I run <code>uwsgi</code>, I get this error:</p>
  
  <pre><code>(env) tsint/ (master)$ uwsgi --socket 127.0.0.1:8080 --protocol=http -w wsgi
  *** Starting uWSGI 2.0.15 (64bit) on [Thu May 11 17:06:43 2017] ***
  ...
  current working directory: /Path/to/tsint
  detected binary path: /Path/to/tsint/env/bin/uwsgi
  *** WARNING: you are running uWSGI without its master process manager ***
  ...
  *** Operational MODE: single process ***
  Traceback (most recent call last):
    File "./wsgi.py", line 1, in &lt;module&gt;
      from tsint import gApp
    File "./tsint/__init__.py", line 1, in &lt;module&gt;
      from flask import Flask
  ModuleNotFoundError: No module named 'flask'
  unable to load app 0 (mountpoint='') (callable not found or import error)
  *** no app loaded. going in full dynamic mode ***
  *** uWSGI is running in multiple interpreter mode ***
  spawned uWSGI worker 1 (and the only) (pid: 36939, cores: 1)
  </code></pre>
  
  <p>Again, it seems uwsgi can't find the installed modules like <code>flask</code>. I've seen
  talk of the <code>-H</code> option to point the the virtualenv, but this causes other problems
  for me, and none of the tutorials showing virtualnv &amp; uWsgi use this option.</p>
  
  <p>Thanks!</p>