I downloaded python 3.3.0 which is latest version and i finished installing now I want to run it in my centOS linux but when i type it in console "python" , python 2.7.0 which is bundled with os installation runs. how can i change it to run 3? I vaguely feel that i have to change the code about path in bin folder or something
Try commands:
python3.3
Or
python3
Python commands and compatibility http://www.python.org/dev/peps/pep-0394/
You should not change system defaults by symlinking Python 3 to Python 2, because this potentially breaks your operating system which relies to the fact that system default python is Python 2.x (referred by start up scripts, applications, etc.)
If you want to run Python 3 when you type command python add the following to your shell configuratin file:
alias python=python3
If running python from your command line, the search order for an executable named python is determined by your $PATH environment variable. echo $PATH will show you your path search order; earlier directories have precedence over latter ones.
If you type which python you'll see what your machine determined to be the first python in your search path.
Most likely, however, is the case where you have a symlink inside /usr/local/bin or /usr/bin named python which points to the python binary.
In most systems, there are actually two symlinks,
python -> pythonX
pythonX -> pythonX.Y
For example,
python -> python2
python2 -> python2.7
You can see whether your python is actually just a symlink with something like
ls -l $(which python)
In my case, this gives me:
/usr/local/bin/python -> python2
Showing that python is a symlink to python2
I could go further by typing
ls -l $(which python2)
In my case, this gives me
/usr/local/bin/python2 -> python2.7
So anyway, you have a few choices
1) Add a symlink from python to the python version you want (probably python3) in some directory higher on the $PATH food-chain -- in a directory earlier in the list. For example, /usr/local/bin is usually higher than /usr/bin.
2) Change your current python symlink to point to the python version you want. Usually this is done by adding the force -f flag to ln.
3) Explicitly stating that you want to run python 3.x by typing python3 on the command line or using #!/bin/env python3 as the hash-bang in your scripts.
4) Alias python to python3 in your .bashrc or equivalent file (eg alias python='/path/to/python3).
The first two options may have wider reaching impact than you expect. For example, they will break the yum package manager, since it only specifies python.
The third might get a bit tedious, but it's more precise, and will allow everything to, by default, use python2 except the scripts you specifically call python3.
The last is a decent compromise, allowing you the ease of just typing python but not affecting other users.
It's all up to you really.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With