Posts Tagged ‘ mac os x ’

Python , Django setup on Mac OS X

i tried to use upper version of python instead of using  the default version on mac. that’s why i install my required version  . but the problem i faced that is python doesn’t know where to look for my libraries which macports installed . it always look into the default version of python library . so the solution is identify the path for my self install . i did that and it works . but for the beginner i write a small tutorial which may be help for very beginner of mac, python and django .

My Environment :

version : Mac OS X (10.6.8 )

OS : snow leopard

default python : 2.6.5

how can you check your default version :

$ python
Requirement :

1. Django 1.5

2.  python 2.7.x

Tools that need to install :

1. macport or HomeBrew: a package manager for Mac OSX that allow you to install UNIX tools.

2. pip : Package install for Python

3. Virtualenv – virtual environment for Python

Installation Steps :

1. install python . i used brew to install .
2. add new Python scripts directory to your PATH
3. install pip .
4. install django
5. Test django
6. create a project
7 . test project

Let’s follow the steps :
open the terminal

1. install python :
$ brew install python --framework

it will take few minutes.Once that’s complete, you’ll have to add the new Python scripts directory to your PATH .

2. add new Python scripts directory to your PATH
export PATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PATH"

3. To install pip,simply run :
$ easy_install pip
if you want to create virtualenv or others python packages then you can easily install through pip . Like next we want to install Django .

4. Install Django:

to install Django simply run this command :
pip install django

5. now just check the which version of django has been installed. simply run this command :
python -c "import django;print(django.get_version())"
it will show you installed django version django .

6. Now let’s create a django project . to create a project simply create your own new directory and under that directory just run that : startproject project_name
a directory will be create by your given project_name say mysite . and it will be look like :

7. now you want to test . for that you need to run server . just simply run this command to run server :
$ python runserver
if successful , then simply run this :

That’s it .

Reference :