Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Install Python 3.6 along with Python 2.7?

Python Newbie here. I just bought a new Mac that came with Python 2.7. I'm using the older version of Python for a class so I need to keep it. I want to install the latest version of Python, 3.6, side by side the older version. The instruction I found online were either outdated or confusing. Can anyone point me in the right direction?

like image 837
johnnewbie25 Avatar asked Jun 19 '17 04:06

johnnewbie25


2 Answers

You can use brew to install python3.

$ brew install python3
$ python # to start the python 2.7
$ python3 # to start the python 3

This is the simplest way to get started with python 3 on macOS.

like image 71
Osman Mesut Ozcan Avatar answered Oct 21 '22 05:10

Osman Mesut Ozcan


if you download anaconda, a very common download for python development, you get a great package manager and a very easy way to create sandboxed environments. After downloading anaconda (for your current Python, so 2.7), you can open up your terminal and enter:

conda create my_new_env_name python=3.6

that will create a new sandboxed environment with python3.6. to use that environment, enter in your shell

source active my_new_env_name

now if you enter python from the shell you're in python3.6, or you can run python somefile.py from the shell to run it in python3.6

This is a great way to maintain and manage different versions of libraries on your system as well. For example, if you need an old version of a specific Python library for a particular project, but don't want to downgrade that library for all your Python code.

More on managing conda environments at the documentation page

like image 28
Max Power Avatar answered Oct 21 '22 03:10

Max Power