title: ImportError: No module named psycopg2 after install
body: <p>I've run <code>sudo pip install psycopg2</code> successfully from my <code>virtualenv</code> on my ubuntu server.</p>
  
  <p>This is the code I'm trying to run:</p>
  
  <pre><code>from flask import Flask
  from flask.ext.sqlalchemy import SQLAlchemy
  
  app = Flask(__name__)
  app.config['SQLALCHEMY_DATABASE_URI'] = "postgresql://USERNAME:PASSWORD@localhost/mydb"
  db = SQLAlchemy(app)
  app.debug = True
  
  class User(db.Model):
      __tablename__ = 'users'
      id = db.Column(db.Integer, primary_key = True)
      name = db.Column(db.String(100))
  
  @app.route('/users/', methods = ['GET'])
  def users():
      query = "SELECT id, name FROM users"
  
      results = User.query.from_statement(query).all()
  
      json_results = []
      for result in results:
          d = {'id' : result.id,
              'name' : result.name}
          json_results.append(d)
  
      res = jsonify(items=json_results)
      res.headers['Access-Control-Allow-Origin'] = '*'
      return res
  </code></pre>
  
  <p>however, when running uWSGI with this file like this :<code>uwsgi --socket 127.0.0.1:8080 --wsgi-file my_app.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191</code>, and call on it with <code>SERVER_URL/users/</code>, I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
      return self.wsgi_app(environ, start_response)
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
      response = self.make_response(self.handle_exception(e))
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
      reraise(exc_type, exc_value, tb)
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
      response = self.full_dispatch_request()
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
      rv = self.dispatch_request()
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File "my_app.py", line 18, in users
      results = User.query.from_statement(query).all()
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 428, in __get__
      return type.query_class(mapper, session=self.sa.session())
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py", line 70, in __call__
      return self.registry()
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/sqlalchemy/util/_collections.py", line 903, in __call__
      return self.registry.setdefault(key, self.createfunc())
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 139, in __init__
      bind=db.engine,
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 780, in engine
      return self.get_engine(self.get_app())
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 797, in get_engine
      return connector.get_engine()
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 473, in get_engine
      self._engine = rv = sqlalchemy.create_engine(info, **options)
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 344, in create_engine
      return strategy.create(*args, **kwargs)
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 73, in create
      dbapi = dialect_cls.dbapi(**dbapi_args)
    File "/home/ubuntu/my_app/my_app_venv/local/lib/python2.7/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 401, in dbapi
      import psycopg2
  ImportError: No module named psycopg2
  [pid: 10902|app: 0|req: 3/3] 74.108.216.27 () {40 vars in 708 bytes} [Sun May 18 01:46:00 2014] GET /users/ =&gt; generated 0 bytes in 13 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
  </code></pre>