PDA

View Full Version : python3 on mac




JonnyFrond
Feb 29, 2012, 01:33 AM
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



Starfox
Feb 29, 2012, 11:42 PM
I'm using the installer from python.org with no trouble whatsoever.

thundersteele
Mar 1, 2012, 01:27 AM
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:
/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
Mar 1, 2012, 09:27 AM
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

rien333
Mar 4, 2012, 05:44 AM
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
Mar 13, 2012, 05:30 PM
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

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
Aug 4, 2012, 05:55 PM
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"