title: Activating Gunicorn through virtualenv with Supervisor for Flask Application
body: <p>I'm trying to deploy a flask application to an ec2 instance using (1) nginx (2) gunicorn, (3) git, and (4) supervisor. I've set up nginx, git, gunicorn, but I've having trouble writing the supervisor script.</p>
  
  <p>I'm unable to get supervisor to launch gunicorn within the context of the virtualenv. </p>
  
  <p>When I run <code>gunicorn run:app</code> outside of the virtualenv it returns</p>
  
  <pre><code>ImportError: No module named flask
  </code></pre>
  
  <p>When I run the same command within the virtualenv it works just fine.</p>
  
  <p>When I run the same command outside of the virtualenv but specify the gunicorn in the virtual env (i.e <code>/var/www/sitename/env/bin/gunicorn run:app</code>) it works just fine again. </p>
  
  <p>That's a problem that I couldn't figure out, but I figured if I could just have supervisor run gunicorn inside the virtualenv it wouldn't be a problem, but I'm not able to do that either. </p>
  
  <p>I've tried adding two programs in the supervisor script, one to launch the virtual environment and the other for gunicorn, added the two commands together using quotes which one similar SO answer suggested, using <code>&amp;&amp;</code> to combine activating the virtualenv and launching gunicorn, declaring an <code>environment=PATH=</code> variable, and a number of other options; I just can't get it to work. </p>
  
  <p>I have no idea what I'm doing wrong or what else to try; does anyone know what I can do at this point? </p>
  
  <p>I'm running python3 - I read that supervisor is limited to v2 but someone else mentioned in an answer that it's just a task manager and it shouldn't matter. </p>