Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JonnyFrond

macrumors newbie
Original poster
Jan 15, 2011
9
0
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

Jonny
 

thundersteele

macrumors 68030
Oct 19, 2011
2,984
9
Switzerland
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:
Code:
/usr/bin/python2.6 myprogram.py

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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,743
8,417
A sea of green
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:
Code:
echo $PATH
 

rien333

macrumors regular
Jun 29, 2010
167
0
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.
 

Bill McEnaney

macrumors 6502
Apr 29, 2010
295
0
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:
Code:
echo $PATH
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?
 

DavidTheExpert

macrumors regular
Apr 20, 2012
199
351
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 foo.py" it will run with python 2. You need to say "python3 foo.py"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.