1

On my Mac OS X Lion, I type the following in Terminal:

hobbes3@hobbes3:~$ which python
/usr/local/bin/python
hobbes3@hobbes3:~$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
hobbes3@hobbes3:~$ /usr/local/bin/python
Python 2.7.2 (default, Feb 23 2012, 00:05:44) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Part of my /usr/local/bin/ looks like this:

lrwxr-xr-x   1 root  wheel    32B Feb 23 00:07 pydoc -> ../Cellar/python/2.7.2/bin/pydoc
lrwxr-xr-x   1 root  wheel    33B Feb 23 00:07 python -> ../Cellar/python/2.7.2/bin/python
lrwxr-xr-x   1 root  wheel    40B Feb 23 00:07 python-config -> ../Cellar/python/2.7.2/bin/python-config
lrwxr-xr-x   1 root  wheel    36B Feb 23 00:07 python2.7 -> ../Cellar/python/2.7.2/bin/python2.7
lrwxr-xr-x   1 root  wheel    43B Feb 23 00:07 python2.7-config -> ../Cellar/python/2.7.2/bin/python2.7-config
lrwxr-xr-x   1 root  wheel    34B Feb 23 00:07 pythonw -> ../Cellar/python/2.7.2/bin/pythonw
lrwxr-xr-x   1 root  wheel    37B Feb 23 00:07 pythonw2.7 -> ../Cellar/python/2.7.2/bin/pythonw2.7

Why is it that the first time I type python I get v2.7.1, but when I type the full path /usr/local/bin/python I get v2.7.2?

I installed v2.7.2 using homebrew, and I would like to use that version because I believe my Django is installed under v2.7.2 python.

hobbes3
  • 635

2 Answers2

4

Because poor bash is confused. Clear python's hash entry.

hash -d python
  • Thanks! Worked great.

    I also have a symbolic link that makes /usr/local/bin/vi follow /usr/local/bin/mvim which is MacVim, a GUI Vim for Mac. But typing hash -d vi didn't work. Typing vi still gives me the default vi. Any idea on this as well?

    – hobbes3 Feb 23 '12 at 05:42
  • Similarly which vi gives /usr/local/bin/vi, so it sounds like the same problem. ls -l on /usr/local/bin/ gives lrwxr-xr-x 1 root wheel 19B Feb 9 23:32 vi -> /usr/local/bin/mvim – hobbes3 Feb 23 '12 at 05:43
  • Just do a rehash, which will rebuild the entire hash table from scratch. – wjv Apr 12 '16 at 09:41
0

In a nutshell the reason they are different is because you're calling them differently.

  • $ python asks the system for the default version of python. This is the same as doing env python. Typically if you ran which python it would show you the path to what it would run.
  • $ /usr/local/bin/python executed the thing at that path

Most unix like OS's have have a concept similar to "Alternatives" in linux ("Ports" on some BSD's). That's where the system default interpreter for a language is defined.

https://stackoverflow.com/questions/5846167/how-to-change-default-python-version will give you a basis on how to change it.

Timothy c
  • 396