Installing Python and Django using MacPorts

Use MacPorts to install python (I'm using Python version 2.7 for this demo):
$ sudo port install python27

If successful, MacPorts should give you this informational message: "To make python 2.7 the default (i.e. the version you get when you run 'python'), please run: sudo port select --set python python27" So let's do that:
$ sudo port select --set python python27

If you want to make sure that installation worked, and you have the correct version, check like this:
$ which python
/opt/local/bin/python
 
$ python --version
Python 2.7.8

Using your MySQL server command line, create a MySQL database. I'm using the name 'djangodemo' for this example:
> CREATE DATABASE djangodemo

Install pip:
$ sudo port install py27-pip

If successful, MacPorts should give you this informational message: "To make the Python 2.7 version of pip the one that is run when you execute the commands without a version suffix, e.g. 'pip', run: port select --set pip pip27" Let's do that:
$ sudo port select --set pip pip27

Now we can install Django:
$ sudo pip install Django

Verify that Django is installed:
$ python -c "import django; print(django.get_version())"
1.6.6

Add the Python bin directory to your path. Add this line to your .bash_profile:
export PATH="$PATH:/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin"

If you're using MySQL, install the Python/MySQL connector:
sudo port install py-mysql

Now you can start building your project. The official Django tutorial is a great place to start.

Category:

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.