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 :
django-admin.py startproject project_name
a directory will be create by your given project_name say mysite . and it will be look like :
mysite/
manage.py>
mysite/
__init__.py
settings.py
urls.py
wsgi.py

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

That’s it .

Reference :
1. https://docs.djangoproject.com/en/dev/intro/tutorial01/
2. http://stackoverflow.com/questions/9305154/python-will-not-recognize-macports-installed-packages

About these ads
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: