ubuntu postgres

Python 2.6, Python 2.7, an Ubuntu
kernel can be prepared in EC2 for
Django and Postgresql needs some major libraries not
often included in the core set of libraries. Gcc is the Gnu compiler.
Recent Python versions on instances are Python 2.6.4 and Python 2.7.2

Use apt-get to install postgres, gcc and these libraries

sudo apt-get update
sudo apt-get install postgresql
sudo apt-get install gcc
sudo apt-get install python-dev
sudo apt-get install libpq-dev
sudo apt-get install python-virtualenv
sudo apt-get install python-psycopg2

You probably want a virtual environment

source bin/activate

or

virtualenv nameofnewthing
source nameofnewthing/bin/activate

and pip install Django, gunicorn and dj_database_url

pip install Django
pip install gunicorn
pip install dj-database-url

Flask Python Heroku

 lets start building source code

cd source # MyHerokuProject/source 

We need to create two files for heroku to spin up our application;

pip freeze > requirements.txt
cat >Procfile
web: python hello.py

create your index.html equivalent

cat >hello.py
import os
from flask import Flask
# import BeautifulSoup
import urllib2
import re

app = Flask(__name__)

@app.route('/')
def hello():
return 'Hello World!'

@app.route('/gb')
def goodbye():
return 'Good Bye'

if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)

and lets git it to heroku

git init 
git add .
git commit -m 'init'
heroku create
git push heroku master 

Heroku Setup for Python and Flask

Getting virtualenv – Setuptools, pip, easyinstall on Ububtu

  • Install python setuptools on Ubuntu
  • Install pip on Ubuntu
  • easy_install on Ubuntu
  • virtualenv on Ubuntu – yes, get used to it.
sudo apt-get install python-setuptools
sudo apt-get install python-pip
  • Install Python development libraries, could be optional but we will use it here.
sudo apt-get install python-dev
  •  Get virtual env
sudo apt-get install python-virtualenv

You might also need a public key from your Ubuntu workstation. If your workstation is secure, you can just hit enter for the passphrase.

ssh-keygen -t rsa

Install the heroku toolbelt.

  • Install Heroku toolbelt on Ubuntu
  • Install Heroku toolbelt on AWS running Ubuntu
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh

Now your 127.0.0.1 server is in sync with Heroku libraries.

Lets start a project.

mkdir MyHerokuPyProject
mkdir MyHerokuPyProject/source

Now, logout and login in to get heroku in the PATH, or do this;

 sudo su ubuntu

Log into heroku;

heroku login

You need to make heroku aware of the public key;

heroku keys:add

Ok, let’s make sure everything is set so far by starting up virtualenv

Lets use our project directory;

cd MyHerokuPyProject 

 We will add a virtual environment to our Python Heroku project;

virtualenv vedir --distribute
source vedir/bin/activate

Now we can get bottle like this. Notice that I am getting the bottle library, not the bottle.py library. It’s the same thing, but if you try to fetch bottle.py it will fail. Easy_install is a pythoin installation system, so it knows that that which we seek is a .py hootinanny.

pip install Flask

Add the Python image library, which requires the development library;

pip install pil

— or —

sudo apt-get install python-setuptools
sudo apt-get install python-pip
sudo apt-get install python-dev
sudo apt-get install python-virtualenv
ssh-keygen -t rsa
wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh
mkdir MyHerokuPyProject
mkdir MyHerokuPyProject/source

log out and log in


heroku login
heroku keys:add
cd MyHerokuPyProject
virtualenv vedir --distribute
source vedir/bin/activate
pip install Flask
pip install pil