Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on installing django and running it on my system.

I have a problem though, in this tutorial creating a project is explained by running the command startproject mysite

My issue is that this doesn't work. I changed to the directory where is located and ran the command

chmod +x

with no results. I tried adding the directory with the file to my path without results. I ended up fixing my problem with this command

python /location/of/ startproject mysite

which yielded the outcome I expected. My problem is: What do I need to change/configure such that command startproject mysite

would be sufficient?

Here are some experiments:

21:09~/Desktop/HI/NSN/Polls > startproject mysite
-bash: command not found
21:09~/Desktop/HI/NSN/Polls > ./ startproject mysite
-bash: ./ No such file or directory
21:09~/Desktop/HI/NSN/Polls > python startproject mysite
python: can't open file '': [Errno 2] No such file or directory
21:09~/Desktop/HI/NSN/Polls > /opt/local/lib/python2.4/site-packages/django/bin/ startproject prufa1
-bash: /opt/local/lib/python2.4/site-packages/django/bin/ /opt/local/bin: bad interpreter: Permission denied
21:09~/Desktop/HI/NSN/Polls > sudo /opt/local/lib/python2.4/site-packages/django/bin/ startproject prufa1Password:
sudo: unable to execute /opt/local/lib/python2.4/site-packages/django/bin/ Permission denied
21:09~/Desktop/HI/NSN/Polls > sudo /opt/local/lib/python2.4/site-packages/django/bin/ startproject prufa1sudo: unable to execute /opt/local/lib/python2.4/site-packages/django/bin/ Permission denied
21:09~/Desktop/HI/NSN/Polls > python /opt/local/lib/python2.4/site-packages/django/bin/ startproject prufa1
21:09~/Desktop/HI/NSN/Polls > ls
mysite prufa1

Final edit: The problem is solved, see Ian C's answer for the right solution. Thank you everyone for helping my out, this was very fast!

share|improve this question
What happens (e.g. error message) when it "doesn't work"? Adding to path (or explicitly specifying the folder as in ./ and making it executable should suffice. – Daniel Beck Mar 1 '11 at 20:47
up vote 3 down vote accepted

There's a slightly more generic version of @Matt Jenkins hashbang (!#) tip you can use to make the script a little more portable. Make sure the first line in the file is:

#!/usr/bin/env python
...everything else...

That says "look for a program named python by searching my PATH and run the rest of this script with that program".

You'll also need to set the execute bit on the script with:

chmod +x

I mention this for completeness, noting that you've already done that.

Finally, the PATH variable doesn't actually contain . in it (the current working directory). That's a safety precaution and I don't recommend changing that setup (it keeps you from calling ./rm when you meant the shell's rm for example). So you need to call the script with:

 ./ startproject mysite

That says "look in the current working directory for" instead of "search the PATH variable" which is what happens if you omit the ./ part.

share|improve this answer
Thank you, this works now. – Haffi112 Mar 1 '11 at 21:24

The first line in the file should contain the program that runs the script prefixed by #! (known as hashbang)

For example:

...python code follows...

Then you can set the executable bit on the file and the shell will interpret it as a script using the program found in the first line as the interpreter.

This is often used with shell scripts, for example:


for FILE in `ls`
    echo "Filename: ${FILE}"
share|improve this answer
The head of the script already said #!/path/to/python so I don't understand why it doesn't work >_< (It had the correct path just to prevent misunderstanding) – Haffi112 Mar 1 '11 at 21:12
Is the path to python the right path to python? Check with whereis python – Majenko Mar 1 '11 at 21:13
Yes it's the right path. – Haffi112 Mar 1 '11 at 21:14
Well, now I'm flummoxed... – Majenko Mar 1 '11 at 21:21
Ah, I think I see what's going on here. The file you're trying to run isn't in a known place (i.e., not in your path) but in /opt/local/lib/python2.4/site-packages/django/bin/ You need to add /opt/local/lib/python2.4/site-packages/django/bin/ to your $PATH environment variable, then you can call it just by name. – Majenko Mar 1 '11 at 21:24
  1. Select the file in the Finder by clicking it once.

  2. From the File menu, select Get Info.

  3. In the Info window, click the triangle next to "Open with:" to expand that section of the window.

  4. From the pull-down menu that appears, select the application you wish to use to open the file.

Source: Indiana University - KB: How do I assign an application to open certain file types?

share|improve this answer
What application should I choose to open the file? I'm using python 2.4 with Django 1.2.4. I also don't see how this is relevant to running the command in terminal. – Haffi112 Mar 1 '11 at 20:56
@Haffi112: Python. As for command line, you need the shebang... – Tom Wijsman Mar 1 '11 at 20:58
Yeah I've tried that, it still doesn't work =/ – Haffi112 Mar 1 '11 at 21:12

When you change the file permissions, you have to write this:

sudo chmod +x

Works for me

share|improve this answer
The problem appears to be with the #! line, not with the permissions of the script file. – David Richerby Oct 8 '15 at 10:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .