Python:版本升级(Mac OS X)
Mac OS X 10.8及以后的版本都预装了Python 2.7,但是在Mac上(Unix-like OS)上修改Python的版本并不如Windows方便。这篇文章的目标是要将Mac自带的Python 2.7升级为3.4.
正文部分:
- 下载并安装新版Python
- 将新版Python复制到系统目录下并修改文件的owner
- 注意这里使用cp而不是mv,否则升级完成后某些包还是会引用到安装目录:/Library/Frameworks/...的lib文件夹,例如无法import readline,导致方向键失效。理论上将指向全部改为/System/Library/...下即可,如果你知道怎么修改,请务必留言。
- sudo cp -r /Library/Frameworks/Python.framework/Versions/3.4/ /System/Library/Frameworks/Python.framework/Versions
- sudo chown -R root:wheel /System/Library/Frameworks/Python.framework/Versions/3.4/
- 修改Python连接文件
- 修改Current连接文件
- sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4 /System/Library/Frameworks/Python.framework/Versions/Current
- 删除/usr/bin/下python相关连接文件
- /usr/bin/pydoc
- /usr/bin/python
- /usr/bin/pythonw
- /usr/bin/python-config
- 重新创建/usr/bin/下相应连接文件
- sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4/bin/pydoc3 /usr/bin/pydoc
- sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4/bin/python3 /usr/bin/python
- sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4/bin/python3 /usr/bin/pythonw
- sudo ln -s /System/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4m-config /usr/bin/python-config
- 修改Current连接文件
- 修改.bash_profile,指定用户变量(需重启Terminal才能生效)
- PATH=/System/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}
- export PATH
- 输入python -V查看,应为修改后的版本。
有两个地方值得注意:
- 不要删除Mac自带的Python!因为可能Mac或第三方软件会引用到。使用ls -l /System/Library/Frameworks/Python.framework/Versions 可以发现有2.3到2.7的各个版本的连接文件也印证了这一点。网上搜出来的中文帖大概因为是复制粘贴的原因,全都先删了自带的Python再说,不知是出于什么心态。附带Python.org的原文:
- The Apple-provided build of Python is installed in /System/Library/Frameworks/Python.framework and /usr/bin/python, respectively. You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software. Remember that if you choose to install a newer Python version from python.org, you will have two different but functional Python installations on your computer, so it will be important that your paths and usages are consistent with what you want to do.
- Python 2.7以后,将/usr/bin/python和/usr/bin/pythonw共同指向/System.../Versions/3.4/bin/python3即可,在我新安装Python版本的bin/下是没有pythonw这个命令。附带原文:
-
With older versions of Python, there is one Mac OS X quirk that you need to be aware of: programs that talk to the Aqua window manager (in other words, anything that has a GUI) need to be run in a special way. Use pythonw instead of python to start such scripts.With Python 3.4, you can use either python or pythonw.
-
由于本人接触Linux和Python的时间较短,有错误或可以有更精简的步骤欢迎提出来讨论。_(:3」∠)_
Python:版本升级(Mac OS X)的更多相关文章
- 解决mac OS 10.9 下python 在terminal下崩溃的问题
Python 2.7.6 release candidate 1 was released on October 26, 2013. This is a 2.7 series bugfix relea ...
- 在 Mac OS X 10.9 搭建 Python3 科学计算环境
安装 Homebrew 使用 Homebrew 管理 Python 版本.在 Terminal/iTerm2 输入: $ ruby -e "$(curl -fsSL https://raw. ...
- 在mac os下的Apache服务器的cgi中运行python
我是搬运工.. Running Python Programs on the Mac OS X Apache Web Server The Mac OS X operating system incl ...
- mac os去除去除.DS_Store文件--使用python和go(原创)
.DS_Store (英文全称 Desktop Services Store)是一种由苹果公司的Mac OS X操作系统所创造的隐藏文件,目的在于存贮文件夹的自定义属性,例如文件们的图标位置或者是背景 ...
- Python 学习之中的一个:在Mac OS X下基于Sublime Text搭建开发平台包括numpy,scipy
1 前言 Python有许多IDE能够用,官方自己也带了一个,Eclipse也能够. 但我在使用各种IDE之后,发现用Sublime Text是最好用的一个.因此.我都是用Sublime Text来编 ...
- 转-在Mac OS上搭建Python的开发环境
在Mac OS上搭建Python的开发环境 本文转载自:http://www.jb51.net/article/76931.htm 一. 安装python mac系统其实自带了一个python的执 ...
- MAC OS环境下搭建基于Python语言的Selenium2自动化测试环境
#1安装Python Mac OS上自带python2.7,在此介绍安装python3.x版本 去官网下载Python for MAC版本 https://www.python.org 安装文件为pk ...
- 在Mac OS上搭建Python的开发环境
本文转载自:http://www.jb51.net/article/76931.htm 一. 安装python mac系统其实自带了一个python的执行执行环境,用来运行python还行,但是开发可 ...
- Mac OS X 下安装python的MySQLdb模块
参考资料: mac os x下python安装MySQLdb模块 http://www.codeif.com/post/1073/ MAC OSX使用Python安装模块有关问题 http:// ...
随机推荐
- 测试mysql
sysbench 测试mysql TODO emacs
- css实现标题文字过长截取...
css实现网页中文字过长截取... title class应该这样写: .title{ width:300px; white-space:nowrap; overflow:hidden; text-o ...
- UART速度的问题
1 原来UART实验的,速度被设置成9600,因为UART,在计算速度的时候带的是96002 后来一次学习的时候,ADC用到串口打数据,那么他的串口速度任然是9600,原来用UBOOT中的速 度则是1 ...
- ctci4.1
; ) ; ) return false; else return true; }
- Git的基础学习
https://www.w3cschool.cn/git/git-install-setup.html 一.安装 Git官网下载,安装,操作步骤可以百度 二.用户信息配置 配置个人用户名称和邮箱地址: ...
- HDU1595-最短路-删边
find the longest of the shortest Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/32768 ...
- 翻译"Python编程无师自通——专业程序员的养成"
这本书在 畅销Python编程类入门书,美国亚马逊Kindle编程类排行榜榜一. 开始初学python,也有不少书了,不想在白花钱(买了就放那里不看了),看一个英文文档的原著,准备每天翻译一点,放到b ...
- vue.js的安装部署+cnpm install 安装过程卡住不动----亲测可用
1.到Node.js的官网下载node node.js的下载地址,下载完成后,我在d盘新建一个文件夹“node”, 安装到node目录下(安装之后环境变量自动配置了,自己无需再配),比如我的安装路径是 ...
- [转载]java获取word文档的条目化内容
在开发Web办公系统或文档系统时,PageOffice组件是众所周知的在线处理微软word/ppt/excel文档的强大工具,它对WORD文档的各种处理在API层面进行了封装,屏蔽了Office VB ...
- centos7 iptables替换firewall
Disable Firewalld Service. [root@rhel-centos7-tejas-barot-linux ~]# systemctl mask firewalld Stop Fi ...