I have a Python script that I run which needs to execute under a special environment, so I would run the program like so from my working directory (~/project/src):

python manage.py shell

This opens up an interactive shell for me to start typing my own commands.

I have another set of administrative activities that I would like to house in another directory (~/project/admin). The manage.py is really finicky about running from the working directory. So, to make this whole thing work, I made a script which starts off like so:

#!/usr/bin/python ../src/manage.py shell

There are a couple problems with this. The first is that it doesn't work:

/usr/bin/python: can't open file '"/../src/manage.py" shell': [Errno 2] No such file or directory
  • How do you specify multiple parameters to the interpreter?
  • How do I change the working directory?
  • This looks like a Django environment. You may get better responses on stackoverflow.com – Doug Harris Feb 2 '11 at 16:44
  • @Doug: It started out as Django, but has been magnificently altered at this point. My only problem now is script-related, so I figured that should go here. – Travis Gockel Feb 2 '11 at 16:50

You can only specify one argument to the interpreter. I don't think you can use relative directories in it either.

I would suggest that you wrap what you need to do in a shell script or a Python script that uses Popen() to call it perhaps.


Assuming that I'm correct in my guess that you're in a Django environment...

Take a look at James Bennet's article about Standalone Django Scripts. Look at the section about "Use setup_environ()" which mentions that this is "exactly how Django’s own manage.py script handles settings".

There's a similar question on stackoverflow which will probably help you as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.