Reputation: 235
I installed python using the command: brew install python3
Now when I use 'which python', path is '/usr/bin/python' and when I use 'which python3' path is 'usr/local/bin/python3'
Shouldn't it fetch the same path ? As python3, which is a version, still falls under python ?
I just am not clear as to why different paths are thrown. Please Explain!
Upvotes: 0
Views: 4312
Reputation: 3306
Python is a program, that will take inputs, and interpret them. How will it interpret them ? Following a set of rules, written in a lot of files. Where are these files written ? Somewhere the program knows. And by default, the 2 paths you have are the paths it knows where to go.
Python2 and Python3 have different files, because even if they have the same base, they are not same and behave differently. Hence the 2 differents paths.
Though, through the years, people have come up with solution to avoid these "python version collisions" on computers : it is called a virtualenv.
Virtualenv is basically a script that will contain a whole new python (at the version you wish you install it), and, when you "activate" it, you will be able to use python
, and have the version you wish to develop with. Doing this, everyone is able to only use python
and still use different versions depending of the program you with to use.
Example : You have python
on your system which writes Python 2.7.12
when you do python --version
. If you instantiate your virtualenv (see the doc), and then use python --version
again, you might see something else along the lines of Python 3.6.8
. Your former computer, or other scripts, can still use the previous python version, and you new script can use the new one, without any conflicts.
Upvotes: 1