Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Python 3 alongside Python 2 problematic?

My programming literacy is very basic, but I like programming and I have been taking some MOOC's to bring me into the 21st century.

I started off by taking a course in Python and installed 2.7.11 (from https://www.python.org/downloads/), now I am onto another course that requires Python 3.x

Can I simply install Python 3.x alongside the 2.x version (on my Mac)? Or, will that create all kinds of conflicts and problems? To add to the picture, I am just using the IDLE that comes along with the download.

If the solution involves a bunch of terminal line commands, or coordinating 3 additional downloads of other packages to make it happen, it is already out of my league. Like I said, I am coming into this as nearly a complete novice.

Thanks for you help.

like image 268
fractalgreg Avatar asked Feb 27 '16 16:02

fractalgreg


People also ask

Why are Python 2 and 3 not compatible?

Python 2 has more complicated syntax than Python 3. Python 3 has an easier syntax compared to Python 2. A lot of libraries of Python 2 are not forward compatible. A lot of libraries are created in Python 3 to be strictly used with Python 3.

Can I have both Python 2 and Python 3?

You can easily maintain separate environments for Python 2 programs and Python 3 programs on the same computer, without worrying about the programs interacting with each other. Switching to an environment is called activating it. Now you have two environments with which to work.

Can I have Python 2 and 3 installed at the same time Mac?

Yep, you can install another python 2.7 through pyenv. It will install that python in $PYENV_ROOT/versions. The other python 2.7 installed through homebrew may appear as "system" when you execute "pyenv versions".

Can I install both Python 2 and 3 on Windows?

In order to execute both python version change the python.exe to python2.exe where python2 is located and python.exe to python3.exe where python3 is located.


2 Answers

This might help anyone having Error: python 2.7.14 is already installed when trying to install python3 with brew install python3. Due to python2.7 being retired on 2020, python3 is now the same as python and python2 is python@2.

To fix the error, just run brew upgrade python and if you still want python2 you can install it by brew install python2. In my case I did not have to run the final command and I had both python installed.

like image 153
Kanyi Avatar answered Sep 27 '22 22:09

Kanyi


It shouldn't create any conflicts simply install python3 with brew install python3, also you get more info for doing it correctly in What is the correct way to install python on OS X? question.

NOTE: After installing python3 you would have two python interpreters python3 and python2.7, your python points to python2.7 as long as you don't change it, in other words your default python interpreter is python2.7 and do not change it without serious reason for that.

To run python3 scripts execute them with your python3 interpreter, tools like pip, easy_install, virtualenv for python3 shall be installed with that interpreter (python3).

like image 42
Andriy Ivaneyko Avatar answered Sep 27 '22 23:09

Andriy Ivaneyko