-2

I initially used python 2.7 on my Mac, how can I now run 3.6 from the terminal? I have installed 3.6, but cannot find any instructions how to make 3.6 the default option.

Sebastian Łącki
  • 167
  • 1
  • 2
  • 14
  • Installed how? If you're using MacPorts or HomeBrew to run your installations, that tool will have its own mechanism for selecting defaults. – Charles Duffy May 23 '17 at 15:43
  • It'd also be a bad idea to make this the default, given the sharp incompatibilities between Python 2 and Python 3, and you could run the risk of deeply breaking something in your OS behind it. – Makoto May 23 '17 at 15:44
  • 1
    anyway if both are installed usually to choose the 3.x just type python3 – Marco smdm May 23 '17 at 15:44
  • See http://www.janosgyerik.com/working-with-different-versions-of-python-on-osx-using-macports/ and related question https://stackoverflow.com/questions/5846167/how-to-change-default-python-version – Mihai8 May 23 '17 at 15:48
  • I was trying to run python program and I didn't realize I needed to use python3 instead of python to run python version 3.6 – Sebastian Łącki May 23 '17 at 15:50
  • Thanks! Got it... – Sebastian Łącki May 23 '17 at 15:51
  • @SebastianŁącki you can also add `alias python="python3"` to your `.bash_profile` on MacOS so you can use `python` to call `python3` on the commandline – quantik May 23 '17 at 15:59

2 Answers2

1

You can specify the python version you want when running the program:

For Python 3.x

python3 filename.py

For Python 2.x:

python filename.py

You can also use an alias to specify the specific python version by typing this command:

alias python="python3"
Ajax1234
  • 69,937
  • 8
  • 61
  • 102
0

In the cmd line type python3 where you would type python before.

To check which (and where) is currently the default version use which python

As others have pointed out, it's best to manage your installations through something like pip, Homebrew, or Anaconda. It makes it much easier to keep track of packages and versions.

David Andrei Ned
  • 799
  • 1
  • 11
  • 28