PDA

View Full Version : Python 2.6.1 on 2010 MBP w/ Mac OS X 10.6.5




oberonpw
Dec 2, 2010, 07:56 PM
My 2010 MBP is fully updated according to Software Update, but the version of Python on it is ancient.

It's 2.6.1 and there are some new features of the language in 3.x that I'd like to try out.

What is the recommended way to get the latest version of Python on Snow Leopard? Thanks!



chown33
Dec 2, 2010, 07:59 PM
Google snow leopard python 3

larkost
Dec 2, 2010, 09:24 PM
And note that 2.6.1 is not "ancient". The 2.x and 3.x versions are being developed in parallel, and Python 3.x is not considered ready for production yet. Additionally 3.x has a lot of incompatibilities with 2.x, so requires work to translate things form 2.x to 3.x.

pilotError
Dec 3, 2010, 08:17 AM
You can go directly to python.org and download the tarball.

If you have X-Code on your machine, you can compile it and do the install.

Pretty simple. I had to do this yesterday for something I was working on.

AlmostThere
Dec 3, 2010, 12:51 PM
MacPorts is another option (I use it and it enables switching between versions very easily and version compatibility with other platforms), but it depends what you want to use python for. Another benefit is getting the right architecture (less of an issue with 10.6), where there have been a mis-mash of 32 and 64 bit libraries on 10.5 and AFAIK only Python 2.7 is bundled with 64-bit binaries in the python.org dmgs. This is important if you are calling bindings to C-libraires from python.

As a side note, don't go installing additional packages into the system python. It is used by Apple for Mac OS X software and you may break compatibility (e.g. the numpy package is used internally by Apple and bundled with the system python).

2.6.1 is pretty old, though. 2 years old tomorrow. If it were an iPhone plenty of people on MR would be telling you to dump your old tech :p

excalibur313
Jan 17, 2011, 11:25 PM
Hi everyone,
So I am trying to do a similar thing with my 2010 mbp and I'm going through the lynda python tutorials that are designed for version 3 or better. I installed python from the official website but I can't figure out how I can run .py files from the command line. I keep getting errors and it says my version is the 2.6 one even though I installed the newer one. Once version 3 is installed, how can I call it when running a ./ command in terminal? The readme says that the new version is located in /Library/Frameworks/Python.framework
but when I include that in my script it doesn't run. The readme then says "add the "bin" directory inside the framework to you shell's search path." but I'm not exactly sure how to do that.
Thanks!

BTW the sample that is giving me errors is:
a, b = 0, 1
if a < b:
print('a ({}) is less than b ({})'.format(a, b))
else:
print('a ({}) is not less than b ({})'.format(a, b))

GorillaPaws
Jan 17, 2011, 11:59 PM
...how can I call it when running a ./ command in terminal?

use: /python3 PathToFile.py

jiminaus
Jan 18, 2011, 12:02 AM
The readme then says "add the "bin" directory inside the framework to you shell's search path."

If you haven't done this, this will be why your python script is running with version 2.6. You'll will have been running with the system-supplied python.

but I'm not exactly sure how to do that.

Create a .bash_profile file in your home directory with the following:


PATH=/blah/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
export PATH


Replace blah with the path to Python 3's bin directory. Start a new terminal session and then type:


which python


It will output a path to python. Check that it's the path to the python in Python 3's bin directory. If it's /usr/bin/python, check that the path in your .bash_profile is correct.

excalibur313
Jan 18, 2011, 06:59 AM
Thanks a lot for your help, but I can't get it to work. I am not 100% positive the directory that I am supposed to use for the python 3.1 location. I think that it is:
/Library/Frameworks/Python.framework/Versions/3.1/bin

Also when I make the .bash_history folder in my ~/user directory the PATH line is all one line with the different paths separated by colons right? The export PATH is then on the next line. This is what I am using now:


PATH=/Library/Frameworks/Python.framework/Versions/3.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
export PATH


I tried a new terminal window and even restarting but it doesn't seem to help. I still get the v2.6 when checking in terminal and which python shows the /usr/bin/python version. Thanks again!

jiminaus
Jan 18, 2011, 01:48 PM
The file is is .bash_profile, not .bash_history. You may have to create it. It should be in the same directory as .bash_history.

I just went to install the official Python 3.1 mpkg. I didn't go through with it because I have Python 3 via MacPorts.

The Python 3.1 installer can set up your shell profile for you. Reinstall Python, at the Installation Type step, click Customize. Tick Shell profile updater. Then click Install.

It also turns out that the UNIX command-line tools package is installed by default. So a link to python 3 should also be in /usr/local/bin on your system. Try a path of:


PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin

excalibur313
Jan 18, 2011, 02:05 PM
Hi again,
Yes, I mis spoke but I was editing my bash_profile before. I tried reinstalling python and also editing the bash_profile file and here is the current state after installing twice:

PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
export PATH

# Setting PATH for Python 3.1
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.1/bin:${PATH}"
export PATH

# Setting PATH for Python 3.1
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.1/bin:${PATH}"
export PATH

I know I can probably delete the second recurrance of that, but any time that I go and look at the version number it sees in terminal it still says the old one. (Even after restarting the computer) That is interesting that you installed it using macports, would that be an option for me at this point or no? I have installed macports for other apps and it is a pretty nice program.
Thanks for your help!

jiminaus
Jan 18, 2011, 02:25 PM
That is interesting that you installed it using macports, would that be an option for me at this point or no? I have installed macports for other apps and it is a pretty nice program.


Installing via MacPorts is superior IMHO. Installed the python31 port and then you can use python 3 by using python3.1 instead of plain python. If you installed the python_select port, you can run python_select to change plain python to python 3, if you want.

chown33
Jan 18, 2011, 03:01 PM
Enter this command:
which python

It should output the complete pathname of the python it will use.
Post that output.

Then enter this command:
echo "$PATH"
and post that output.