MAC 上升級python爲最新版本

第1步:下載Python3.4

下載地址以下:

下載Mac OS X 64-bit/32-bit installer
https://www.python.org/downloads/release/python-340/


第2步: 安裝

安裝下載的dmg文件


第3步: 配置  建立下面的script, 改下版本號便可
[plain] view plaincopy在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
bixiaopeng@bixiaopengtekiMacBook-Pro ~$ python --version  
相關文章
相關標籤/搜索