標籤:
第1步:下載Python3.4如下:下載Mac OS X 64-bit/32-bit installerhttps://www.python.org/downloads/release/python-340/第2步: 安裝安裝下載的dmg檔案第3步: 配置 建立下面的script, 改下版本號碼即可[plain] view plaincopy在CODE上查看代碼片派生到My Code片#!/bin/bash #python版號需要修改兩個地方 #1. new_version #sudo -i #得到超級許可權 new_version="3.4" PYPATH=/System/Library/Frameworks/Python.framework/Versions/"$new_version" #第1步移動新版python到mac預設目錄下 echo "move.." mv /Library/Frameworks/Python.framework/Versions/"$new_version" /System/Library/Frameworks/Python.framework/Versions/ #第2步改變使用者目錄的使用者組 echo "chown.." chown -R root:wheel ${PYPATH} #第3步 刪除原來2.7的連結 echo "del.." rm /System/Library/Frameworks/Python.framework/Versions/Current #第4步重新連結到最新版本的python echo "ln.." ln -s ${PYPATH} /System/Library/Frameworks/Python.framework/Versions/Current #第5步刪除舊的命令符號連結 echo "rm.." rm /usr/bin/{pydoc,python,pythonw,python-config} echo "ln bin.." #第6步重建立立新的命令符號連結 ln -s ${PYPATH}/bin/pydoc"$new_version" /usr/bin/pydoc ln -s ${PYPATH}/bin/python"$new_version" /usr/bin/python ln -s ${PYPATH}/bin/pythonw"$new_version" /usr/bin/pythonw ln -s ${PYPATH}/bin/python"$new_version"m-config /usr/bin/python-config python_param_list=`cd /usr/local/bin && ls -al |grep "Python"|awk ‘ORS=" " {print $9}‘` #第7步修複其他連結 for i in $python_param_list;do echo "info: $i" rm -f /usr/local/bin/${i} ln -sv /System/Library/Frameworks/Python.framework/Versions/"$new_version"/bin/${i} /usr/local/bin/${i} done #第8步.環境變數要修改為最新的版本號碼 echo ‘export PATH=/System/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}‘ >> ~/.bashrc exit #退出超級許可權 查看當前python版本[html] view plaincopy[email protected] ~$ python --version
MAC 上升級python為最新版本