如何在 Mac OS X 上安装 Python3.3

Mac OS X 我升级到了 10.9,默认 Python 是 Python2.7,但是使用 Python3 比较多
比如 goagent 需要使用 Python3。使用 Python3 有几种方式。
1、使用 homebrew ,这需要安装 XCode Command Line Tools,再安装 homebrew.
2、使用官方的安装包
http://python.org/download/releases/3.3.3/
http://python.org/ftp/python/3.3.3/python-3.3.3-macosx10.6.dmg
双击安装就行,但是需要进行一些后续配置,配置不住如下:
将安装的文件移动到 /System/Library/Frameworks/Python.framework/Versions 目录下,
因为老版本的 Python 都位于 这个目录下,然后再更新 Current 指向的目录,最后更新符号链接和环境变量。

sudo -i
PYPATH=/System/Library/Frameworks/Python.framework/Versions/3.3
mv /Library/Frameworks/Python.framework/Versions/3.3 /System/Library/Frameworks/Python.framework/Versions/
chown -R root:wheel ${PYPATH}
rm /System/Library/Frameworks/Python.framework/Versions/Current
ln -s ${PYPATH} /System/Library/Frameworks/Python.framework/Versions/Current
rm /usr/bin/{pydoc,python,pythonw,python-config}
ln -s ${PYPATH}/bin/pydoc3.3 /usr/bin/pydoc
ln -s ${PYPATH}/bin/python3.3 /usr/bin/python
ln -s ${PYPATH}/bin/pythonw3.3 /usr/bin/pythonw
ln -s ${PYPATH}/bin/python3.3m-config /usr/bin/python-config
exit

#修复其他链接
for i in pyvenv-3.3 inpyvenv-3.3 \
pyvenv pythonw3.3-32 pythonw3.3 \
pythonw3-32 pythonw3 python3.3m-config \
python3.3m python3.3-config python3.3-32 \
python3.3 python3-config python3-32 python3 \
pydoc3.3 pydoc3 idle3.3 idle3 2to3-3.3 2to3;do
  rm -f /usr/local/bin/${i}
  ln -sv   /System/Library/Frameworks/Python.framework/Versions/3.3/bin/${i} /usr/local/bin/${i}
done

echo 'export PATH=/System/Library/Frameworks/Python.framework/Versions/3.3/bin:${PATH}' >> ~/.bashrc

安装 pip

sudo -i
curl http://python-distribute.org/distribute_setup.py | python3
curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3

历史搜索记录:

Post a Comment

Your email is never shared. Required fields are marked *

*
*