Sunday, August 5, 2012

Configure new Heroku Django project on Linux with Virtualenv


1. Install Heroku Toolbelt:


wget -qO- https://toolbelt.heroku.com/install.sh | sh

then

$ heroku login
Enter your Heroku credentials.
Email: kenneth@example.com
Password:
Could not find an existing public key.
Would you like to generate one? [Yn]
Generating new SSH public key.
Uploading ssh public key /Users/kenneth/.ssh/id_rsa.pub
 
2. Install pip

Install pip and virtualenv for Ubuntu 10.10 Maverick and newer

$ sudo apt-get install python-pip python-dev build-essential 
$ sudo pip install --upgrade pip 
$ sudo pip install --upgrade virtualenv 

For older versions of Ubuntu

  • Install Easy Install
    $ sudo apt-get install python-setuptools python-dev build-essential 
    
  • Install pip
    $ sudo easy_install pip 
    
  • Install virtualenv
    $ sudo pip install --upgrade virtualenv 
    

3. Install virtualenv

pip install virtualenv

4. Activate virtualenv

$ mkdir hellodjango && cd hellodjango
$ virtualenv venv --distribute
New python executable in venv/bin/python
Installing distribute...............done.
Installing pip...............done. 

5. Install Django psycopg2 dj-database-url

$ pip install Django psycopg2 dj-database-url
 
In this step, you might get 
 
Error: pg_config executable not found. 


To solve this
sudo apt-get install libpq-dev python-dev
 
then
$ pip install Django psycopg2 dj-database-url
 
  
6. Initiate new project and run server

$ django-admin.py startproject hellodjango .
 
$ python manage.py runserver
Validating models...

0 errors found
Django version 1.4, using settings 'hellodjango.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C. 

7. Install South
South is an open source package for model migration management for django. Without it, django itself can only add fied to models but not modifying. 
 
8. Create a Pip requirements file

$ pip freeze > requirements.txt

No comments:

Post a Comment