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:// ...
随机推荐
- [解决]JS失效,提示HTML1114: (UNICODE 字节顺序标记)的代码页 utf-8 覆盖(META 标记)的冲突的代码页 utf-8
上网找了找,木有找到相关的解决办法,索性自己试了试. 原页面是这样写的: <html> <head> <meta http-equiv="Content-Typ ...
- Elasticsearch6.0之二:常用语句
// 查看集群状态 GET /_cluster/health?pretty // 查看所有索引配置信息 Get _all/_settings // 查看所有索引状态 GET /_cat/indices ...
- web.xml上下文初始化参数
1.在web.xml文件中配置上下文参数 <!--<context-param>标签声明上下文初始化参数, --> <!-- 上下文初始化的参数可以被应用程序用所有ser ...
- Spring的注解配置与XML配置之间的比较
注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以有效减少配置的工作. 如:使用 JPA 注释配置 ORM 映射时,我们就不需要指定 PO ...
- ES5下的React
按照官方推荐的思路,React使用标准的ES6标准的语法.比如说创建一个类: class Greeting extends React.Component { render() { return &l ...
- 关系型数据库(RDBMS)与 MongoDB 的对应关系
谈一下关系型数据库(RDBMS)与 MongoDB 的对应关系:
- 修改linux系统用户最大线程数限制
linux系统对线程数量有个最大限制,当达到系统限制的最大线程数时使用账号密码ssh到系统时是无法登陆的,会报Write failed: Broken pipe,或者是shell request fa ...
- 多网卡绑定(bond)
通过以下命令查看bond0的工作状态查询能详细的掌握bonding的工作状态,如这个绑定各网卡的工作状态.主备关系.链路侦测时间[root@ASMTS ~]# cat /proc/net/bondin ...
- table 转实体
public class Table2Entity<T> where T : class,new() { public static List<T> GetEntitys(Da ...
- AOP(面向切面)的粗俗理解
百度百科的解释:AOP主要实现的目的是针对业务处理过程中的切面进行提取,它所面对的是处理过程中的某个步骤或阶段,以获得逻辑过程中各部分之间低耦合性的隔离效果. 一个比较绕的概念,简单来说就是把不影响业 ...