Magic Studio

专心做有逼格的APP!

How to update pre-installed python on MacOS

Question

If I download python from the Python website and try to install it with the installer, it installs, but I need to specify that I want the new version of Python when I run my programs from terminal. If I just type:

python app.py

It runs with the old version.

How do can I set the new version as default?

==================================================================================

Answer

I finally found how to do it. The installer made a python 2.6 folder in /Application In this folder is a script called Update Shell Profile.command I just needed to execute it and now it's working.

===================================================================================

Other reference

Two questions:

  1. Where did the new Python get installed?
  2. What does your $PATH look like?

A default set-up on Unix-like systems is that user-installed software gets installed in /usr/local/bin, and most *nix distros put that directory before system-wide directories in the default $PATH variable (which is how your shell knows where to look for programs). That way, if you install something new, the new item gets found first.

However, a default OS X $PATH looks like this:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

The problem is that by putting /usr/local/bin so late, the system-wide Python (which is at /usr/bin and so earlier in your $PATH) keeps getting hit.

My answer is to make my $PATH look like this on a Mac:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin

To do that, create a file .profile in your home directory and add something like this:

#### Let's take care of our $PATH
# A backup of the original $PATH
# /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

# My preferred order - /usr/local goes first, damn it!
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin

Edit: I'm following up here, rather than in comments because it's getting too long for a comment. The line in your .profile with /sw/bin/init.sh comes from the package manager Fink, which I'm assuming you use (or used at some point). The other line seems to suggest that at some point you installed MacPython and it rewrote your $PATH for you. I don't know MacPython, but if it's this site, then it hasn't been updated since 2004. It also doesn't seem to talk about any version of OS X beyond 10.3, which is not very current.

So now I'm more confused: when did you update Python? How did you update it? What version of OS X are you running?

 

posted on 2011-07-06 14:34  Mr 布鲁斯  阅读(448)  评论(0编辑  收藏  举报

导航