Getting macports django and python to work together
Question: I'm a webdeveloper and I have a django project that I need to work on.

I am running mac OSX 10.6.5 on a macbook pro. I used macports to install
django and python 2.6.

I now have some sort of problem, possibly related to my PATH / PYTHONPATH that
prevents me from running django.

In terminal echo $PATH gives:

    
    
    echo $PATH
    /Library/Python/2.6/site-packages:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    

and echo $PYTHONPATH gives nothing.

sudo port installed gives :

    
    
    sudo port installed
    The following ports are currently installed:
    autoconf @2.65_1 (active)
    automake @1.11.1_0 (active)
    bash-completion @1.1_8
    bash-completion @1.2_0 (active)
    bzip2 @1.0.5_3+darwin
    bzip2 @1.0.6_0 (active)
    db46 @4.6.21_6 (active)
    expat @2.0.1_0
    expat @2.0.1_1 (active)
    fontconfig @2.8.0_0+macosx (active)
    freetype @2.3.12_0+macosx (active)
    gdbm @1.8.3_2 (active)
    gettext @0.18_0
    gettext @0.18.1.1_2 (active)
    gperf @3.0.4_0 (active)
    help2man @1.38.2_0 (active)
    ImageMagick @6.6.2-0_0+q16 (active)
    jpeg @8a_0 (active)
    lcms @1.19_2 (active)
    libiconv @1.13.1_0 (active)
    libpng @1.2.43_0 (active)
    libtool @2.2.6b_1+darwin (active)
    libxml2 @2.7.7_0 (active)
    m4 @1.4.14_0 (active)
    ncurses @5.7_0+darwin_10
    ncurses @5.7_1 (active)
    ncursesw @5.7_0+darwin_10
    ncursesw @5.7_1 (active)
    openssl @1.0.0b_0 (active)
    p5-locale-gettext @1.05_2 (active)
    p7zip @9.04_0 (active)
    perl5 @5.8.9_0 (active)
    perl5.8 @5.8.9_3 (active)
    pkgconfig @0.25_0 (active)
    py26-distribute @0.6.14_0 (active)
    py26-django @1.2.3_0+bash_completion (active)
    python26 @2.6.6_0+no_tkinter (active)
    readline @6.1.002_0 (active)
    sqlite3 @3.7.3_0 (active)
    tiff @3.9.2_3+macosx (active)
    xorg-bigreqsproto @1.1.0_0 (active)
    xorg-inputproto @2.0_0 (active)
    xorg-kbproto @1.0.4_0 (active)
    xorg-libice @1.0.6_0 (active)
    xorg-libsm @1.1.1_0 (active)
    xorg-libX11 @1.3.3_0 (active)
    xorg-libXau @1.0.5_0 (active)
    xorg-libXdmcp @1.0.3_0 (active)
    xorg-libXext @1.1.1_0 (active)
    xorg-libXt @1.0.8_0 (active)
    xorg-util-macros @1.7.0_0 (active)
    xorg-xcmiscproto @1.2.0_0 (active)
    xorg-xextproto @7.1.1_0 (active)
    xorg-xf86bigfontproto @1.2.0_0 (active)
    xorg-xproto @7.0.16_0 (active)
    xorg-xtrans @1.2.5_0 (active)
    zlib @1.2.5_0 (active)
    

and when I type python I get:

    
    
    python
    Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
    [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 
    

I'm pretty certain that this is the incorrect version.

When I try and test if django is available to python I get:

    
    
    >>> import django
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: No module named django
    >>> 
    

Could anyone help me figure out what is going on here? I only need to get
django running so that I can view and work on the django project that my
colleague sent me.

Thanks for any help in advance!


Answer: First, Macports writes the file ~/.profile to set its PATH variables. If you
have created a ~/.bash_profile file then ~/.profile will be **ignored**. You
will have to copy the contents over.

To see what python version Macports has selected use:

    
    
    port select --list python
    

which will show you something like this:

    
    
    Available versions for python:
        none
        python25-apple
        python26-apple
        python27 (active)
        python32
    

To tell Macports to use a specific version use:

    
    
    port select --set python python27
    

That should get your python version correct. You can use the python
easy_install to install Django now or use the Macports distribution of Django.

