python3 on mac

Discussion in 'Mac Programming' started by JonnyFrond, Feb 28, 2012.

  1. JonnyFrond macrumors newbie

    Jan 15, 2011
    Hi guys,

    Has anyone successfully got python3 to work on a mac?

    I am trying to learn python, and have a book that teaches python3. my Mac only have python 2.7.2. So I install python3, yet every time I try to run a program I have written, it tries to run in python 2 and stops with syntax errors.

    I know my code is good, it is a tiny program the problem is with
    'print (end=" ")'
    Which works with python3 but not python2.

    How can I get this to work, so that I can learn this language easier? oh, and without compromising my mac.

    Python3 doesn't have to be default, but I need to know how to run executables with it

    Kind regards

  2. Starfox macrumors 6502


    Apr 7, 2011
    I'm using the installer from with no trouble whatsoever.
  3. thundersteele macrumors 68030

    Oct 19, 2011
    How do you launch the program?

    You could try to launch it using the full path to the python 3 executable, wherever it is located. Example:
    I don't have a python 3 installation, so I use an example of running an older version instead of python 2.7 which is default on my system.

    Depending on what you want to do eventually, learning python 2 might be more useful. Many useful libraries are still based on python 2.X. For GUI programming, it seems that at least TKinter is compatible with python 3 now.
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Post the actual command-line you used. The one that you wanted to run python3, but that ran the builtin python instead.

    Post the exact title, author, and edition of the book you're using.

    Also, run the following command and post the complete output:
    echo $PATH
  5. rien333 macrumors regular

    Jun 29, 2010
    The Netherlands
    I think the problem is in the print statement, if I understand you correctly. One of the differences between python 2 and 3 is that 'print' is a function in python 3 instead of the thing it is in python 2. (I don't how to call it in python 2)

    So print( "Hello, world!") in python 3 has to be written as print "Hello, world!" in python 2. (so without the parentheses.) I think you will be fine with Python 2.7.2 on a beginner level as long as you remember this.
  6. Bill McEnaney macrumors 6502

    Apr 29, 2010
    After I built and installed Python 3, I had more than one version of Python in /usr/local/bin. Maybe OP just needs to look there for that version of Python?
  7. DavidTheExpert macrumors regular

    Apr 20, 2012
    When you run a python script in terminal you need to use the python3 command instead of python. Even after you install python 3, if you say "python" it will run with python 2. You need to say "python3"

Share This Page