Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 29, 2012, 01:33 AM   #1
JonnyFrond
macrumors newbie
 
Join Date: Jan 2011
python3 on mac

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
JonnyFrond is offline   0 Reply With Quote
Old Feb 29, 2012, 11:42 PM   #2
Starfox
macrumors regular
 
Join Date: Apr 2011
I'm using the installer from python.org with no trouble whatsoever.
Starfox is offline   0 Reply With Quote
Old Mar 1, 2012, 01:27 AM   #3
thundersteele
macrumors 68030
 
Join Date: Oct 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:
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.
thundersteele is offline   0 Reply With Quote
Old Mar 1, 2012, 09:27 AM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
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
chown33 is offline   0 Reply With Quote
Old Mar 4, 2012, 05:44 AM   #5
rien333
macrumors regular
 
Join Date: Jun 2010
Location: 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.
__________________
Macrumors newbie, happy to be here! (And sorry if any of my English is incorrect)
rien333 is offline   0 Reply With Quote
Old Mar 13, 2012, 05:30 PM   #6
Bill McEnaney
macrumors 6502
 
Join Date: Apr 2010
Quote:
Originally Posted by chown33 View Post
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?
Bill McEnaney is offline   0 Reply With Quote
Old Aug 4, 2012, 05:55 PM   #7
DavidTheExpert
macrumors member
 
Join Date: Apr 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 foo.py" it will run with python 2. You need to say "python3 foo.py"
__________________
Get viewed with Fireviews.com
DavidTheExpert is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
iMessage on Mac -BigMac- Mac OS X 10.7 Lion 50 Feb 19, 2012 10:01 PM
How to play Sonic Adventure DX (for PC) on a Mac without loading Windows alexreich Mac and PC Games 0 Feb 7, 2012 12:23 AM
Mac Os gone and only windows shows up, Help me. Sarwanster Windows, Linux & Others on the Mac 2 Sep 24, 2011 01:32 PM
Will VGA Splitter work for 2 Monitors on mini displayport to VGA on Mac Mini 2010? QuakeProd Mac mini 10 Mar 30, 2011 02:29 AM


All times are GMT -5. The time now is 05:37 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC