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?

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值