views:

770

answers:

2

I run at a cloned Django repository

python manage.py runserver

I get

Traceback (most recent call last):
  File "manage.py", line 2, in <module>
    from django.core.management import execute_manager
ImportError: No module named django.core.management

The problem is in my PYTHONPATH according to MacPorts' IRC.

I run

ls -l $(which python)

I get

lrwxr-xr-x  1 root  wheel    68B Jan 29 12:27 /usr/local/bin/python -> ../../../Library/Frameworks/Python.framework/Versions/2.6/bin/python

This command suggests according to krunk that my PATHs are incorrect: /opt/local/... should be before /usr/local/...

However, I am not sure what he means.

My PYTHONPATH in ~/.zshrc is

export PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/:$HOME/.python_libraries:

where /opt/local/... is the first PATH as krunk suggests.

I run

which $PYTHONPATH
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/:/Users/Sam/.python_libraries: not found

My PYTHONPATH has something wrong: apparently the /opt/locall/... is not right.

How can you get the PYTHONPATH correct?

+1  A: 

Your problem is not with PYTHONPATH, it's with PATH itself -- echo $PATH to see it, export PATH=whatever to change it (you can do that in your ~/.bashrc for example).

You'll see that in your current PATH /usr/local/bin comes before /opt/local/bin -- you need to swap them if you want python to be running from your MacPorts. Alternatively, of course, you can choose to explicitly run /opt/local/bin/python ...

Alex Martelli
+1  A: 

I would recommend not using macports, and install Python using Jesse Noller's instructions at http://jessenoller.com/2009/03/16/so-you-want-to-use-python-on-the-mac/

His instructions assume Bash, but should work the same for zsh.

Van Gale