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

How do I set the default python for running py files without "python" keyword i.e $ startproject" in bash shell?

share|improve this question

That depends on the first line in the .py file (the "shebang line"). Commonly you'll see something like this:


In which case, the script when run as a standalone executable will run using the version of Python at /usr/bin/python2.6. Why this version of python? It might have been hard-coded into the script, but more likely it was set automatically when you installed the script. E.g. when you installed Django you either:

  1. Downloaded the source and ran python - in which case the script gets installed to run with the version of python you ran using
  2. Ran easy_install django - in which case the script gets installed to run with the same version of python that easy_install (also a Python script) uses. (This is why you'll often see multiple versions of easy_install listed, e.g. I have easy_install-2.5, easy_install-2.6 and easy-install-2.7 available. When I just type easy_install it uses easy_install-2.6.)
  3. Ran pip install django - same deal as with easy_install, pretty much.

To run the script with another version of Python you can change the shebang line (e.g. to read #!/usr/bin/python2.7) or specify your python on the command line (e.g. /path/to/python2.7 /path/to/ args). Note however that scripts such as are just a front-end to a larger set of libraries (in this case, Django), and those libraries will have been installed by default in the library location for a specific version of Python. For example, if the first line of indicates that it's running under Python 2.6, the Django libraries will have been installed in a Python 2.6-specific library directory, and they won't be available by default to e.g. Python 2.7.

In other cases you'll see a shebang line like this:

#!/usr/bin/env python

In which case, the script will run with whichever version of Python you get when you just type python at your command line. You will be able to change the version of python that scripts with this kind of shebang line have by, for example, altering your PATH environment variable so that your shell finds python in a different directory.

In either case, you should consider checking out virtualenvwrapper, an extension to virtualenv. It allows you to quickly and easily set up multiple virtual environments for Python projects, each with its own default Python version and libraries.

Update: since your question mentions OS X it's also worth mentioning that in OS X, /usr/bin/python runs a user-configurable version of Python. See the OS X python manpage for details.

share|improve this answer

find the long version here:

in short:

defaults write Version x.x

/usr/bin/python -V
-> Python x.x.y

for a quick shift inside running CLI session do

/usr/bin/python -V
-> Python 2.5.6

back to default standard python

share|improve this answer
If the same answer is applicable to more than one question, that's an indication that they questions involved are duplicates. If so, please "flag" the question as duplicate; that way the more experienced members of the community can take a look and determine whether they are, in fact, duplicates. – Michael Kjörling May 19 '15 at 11:31

You must log in to answer this question.

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