Reputation: 626
I'm using a Mac 10.6.8 computer and, before today, whenever I started up the terminal and typed "python" it would tell me I was using python 2.6.1, even though I had already installed 2.7.3 from Python.org a few months ago:
cd
python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
So I searched online to see how I could change to Python 2.7.3 when using the python interpreter. I installed it from Python.org and according to this question ( Mac OSX: Switch to Python 2.7.3 ) the default locations of Apple and Python.org's python differ. I then moved to where Python.org python was located and simply typed python:
cd /usr/local/bin
python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
Everything's as expected, since python should call the version that's in its directory first. I closed the old terminal and opened a new window, so I'm back at my home directory. But this time when I use python, I see that I'm back at 2.7.3.
cd
python
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
This is what I wanted, but I'm confused as to why this worked. All I did was I went to the place where 2.7.3 was located and typed "python." I didn't change any variables, do the changes reflected here ( https://superuser.com/questions/35256/how-can-i-change-the-default-python-version-on-snow-leopard ) or here ( how to change default python version? ), alter my bash files, etc. so why did my actions above make the default python suddenly switch to 2.7.3?
Let me know if you need more info.
Upvotes: 0
Views: 189
Reputation: 1121864
Just typing python
by itself will not load the python from the local directory. It'll be looked up in your $PATH
environment variable instead. Use ./python
to invoke a binary in the local directory.
That means that your second python
call already was different from the first; the Python installer must have added the new location to your PATH
variable (usually via .bashrc
or similar shell startup construct).
Use /usr/bin/python
to run the Mac OS X default, or use python2.6
to look up a python binary by version.
Upvotes: 2