how to change default python version?
I have installed python 3.2 in my mac. After I run /Applications/Python 3.2/Update Shell Profile.command, it's confusing that when I type python -V in Terminal it says that Python 2.6.1, how can I change the default python version?
This is probably desirable for backwards compatibility.
Python3 breaks backwards compatibility, and programs invoking 'python' probably expect python2. You probably have many programs and scripts which you are not even aware of which expect python=python2, and changing this would break those programs and scripts.
The answer you are probably looking for is You should not change this.
You could, however, make a custom alias in your shell. The way you do so depends on the shell, but perhaps you could do alias py=python3
If you are confused about how to start the latest version of python, it is at least the case on Linux that python3 leaves your python2 installation intact (due to the above compatibility reasons); thus you can start python3 with the python3 command.
On Mac OS X using the python.org installer as you apparently have, you need to invoke Python 3 with python3, not python. That is currently reserved for Python 2 versions. You could also use python3.2 to specifically invoke that version.
$ which python /usr/bin/python $ which python3 /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 $ cd /Library/Frameworks/Python.framework/Versions/3.2/bin/ $ ls -l total 384 lrwxr-xr-x 1 root admin 8 Apr 28 15:51 2to3@ -> 2to3-3.2 -rwxrwxr-x 1 root admin 140 Feb 20 11:14 2to3-3.2* lrwxr-xr-x 1 root admin 7 Apr 28 15:51 idle3@ -> idle3.2 -rwxrwxr-x 1 root admin 138 Feb 20 11:14 idle3.2* lrwxr-xr-x 1 root admin 8 Apr 28 15:51 pydoc3@ -> pydoc3.2 -rwxrwxr-x 1 root admin 123 Feb 20 11:14 pydoc3.2* -rwxrwxr-x 2 root admin 25624 Feb 20 11:14 python3* lrwxr-xr-x 1 root admin 12 Apr 28 15:51 python3-32@ -> python3.2-32 lrwxr-xr-x 1 root admin 16 Apr 28 15:51 python3-config@ -> python3.2-config -rwxrwxr-x 2 root admin 25624 Feb 20 11:14 python3.2* -rwxrwxr-x 1 root admin 13964 Feb 20 11:14 python3.2-32* lrwxr-xr-x 1 root admin 17 Apr 28 15:51 python3.2-config@ -> python3.2m-config -rwxrwxr-x 1 root admin 25784 Feb 20 11:14 python3.2m* -rwxrwxr-x 1 root admin 1865 Feb 20 11:14 python3.2m-config* lrwxr-xr-x 1 root admin 10 Apr 28 15:51 pythonw3@ -> pythonw3.2 lrwxr-xr-x 1 root admin 13 Apr 28 15:51 pythonw3-32@ -> pythonw3.2-32 -rwxrwxr-x 1 root admin 25624 Feb 20 11:14 pythonw3.2* -rwxrwxr-x 1 root admin 13964 Feb 20 11:14 pythonw3.2-32*
If you also installed a Python 2 from python.org, it would have a similar framework bin directory with no overlapping file names (except for 2to3).
$ open /Applications/Python\ 2.7/Update\ Shell\ Profile.command $ sh -l $ echo $PATH /Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.2/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin $ which python3 /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 $ which python /Library/Frameworks/Python.framework/Versions/2.7/bin/python $ cd /Library/Frameworks/Python.framework/Versions/2.7/bin $ ls -l total 288 -rwxrwxr-x 1 root admin 150 Jul 3 2010 2to3* lrwxr-x--- 1 root admin 7 Nov 8 23:14 idle@ -> idle2.7 -rwxrwxr-x 1 root admin 138 Jul 3 2010 idle2.7* lrwxr-x--- 1 root admin 8 Nov 8 23:14 pydoc@ -> pydoc2.7 -rwxrwxr-x 1 root admin 123 Jul 3 2010 pydoc2.7* lrwxr-x--- 1 root admin 9 Nov 8 23:14 python@ -> python2.7 lrwxr-x--- 1 root admin 16 Nov 8 23:14 python-config@ -> python2.7-config -rwxrwxr-x 1 root admin 33764 Jul 3 2010 python2.7* -rwxrwxr-x 1 root admin 1663 Jul 3 2010 python2.7-config* lrwxr-x--- 1 root admin 10 Nov 8 23:14 pythonw@ -> pythonw2.7 -rwxrwxr-x 1 root admin 33764 Jul 3 2010 pythonw2.7* lrwxr-x--- 1 root admin 11 Nov 8 23:14 smtpd.py@ -> smtpd2.7.py -rwxrwxr-x 1 root admin 18272 Jul 3 2010 smtpd2.7.py*
Check the location of python 3
$ which python3 /usr/local/bin/python3
Write alias in bash_profile
vi ~/.bash_profile alias python='/usr/local/bin/python3'
Confirm python command
$ python --version Python 3.6.5
Old question, but alternatively:
virtualenv --python=python3.5 .venv source .venv/bin/activate
Change the "default" Python by putting it ahead of the system Python on your path, for instance:
Do right thing, do thing right!
--->Zero Open your terminal,
--Firstly input python -V, It likely shows:
-Secondly input python3 -V, It likely shows:
--Thirdly input where python or which python, It likely shows:
---Fourthly input where python3 or which python3, It likely shows:
--Fifthly add the following line at the bottom of your PATH environment variable file in ~/.profile file or ~/.bash_profile under Bash or ~/.zshrc under zsh.
-Sixthly input source ~/.bash_profile under Bash or source ~/.zshrc under zsh.
--Seventhly Quit the terminal.
---Eighthly Open your terminal, and input python -V, It likely shows:
I had done successfully try it.
Others, the ~/.bash_profile under zsh is not that ~/.bash_profile.
The PATH environment variable under zsh instead ~/.profile (or ~/.bash_file) via ~/.zshrc.
Help you guys!
According to a quick google search, this update only applies to the current shell you have open. It can probably be fixed by typing python3, as mac and linux are similar enough for things like this to coincide. Link to the result of google search.
Also, as ninjagecko stated, most programs have not been updated to 3.x yet, so having the default python as 3.x would break many python scripts used in applications.
I am using OS X 10.7.5 and Python 3.4.2. If you type python3 and what you want to run it will run it using python 3. For example pyhton3 test001.py. That ran a test program I made called test001. I hope this helps.
My Computer -> Properties -> Advanced -> Environment Variables -> System Variables
Suppose you had already having python 2.7 added in path variable and you want to change default path to python 3.x
then add path of python3.5.x folder before python2.7 path.
open cmd: type "python --version"
python version will be changed to python 3.5.x
sudo mv /usr/bin/python /usr/bin/python2 sudo ln -s $(which python3) /usr/bin/python
This will break scripts, but is exactly the way to change python. You should also rewrite the scripts to not assume python is 2.x. This will work regardless of the place where you call system or exec.