Mac打造python2 python3开发环境

最新版的MacOS Sierra默认带的python环境仍然为2.7.10,本文将介绍使用Brew安装python3.5并做简单的配置,打造python2,python3共存的开发环境

直接尝试brew安装,提示需要执行brew link gdbm

thatsitdeMacBook-Pro:~ thatsit$ brew install python3
Updating Homebrew...
Error: You must `brew link gdbm` before python3 can be installed
thatsitdeMacBook-Pro:~ thatsit$

按提示执行brew link gdbm,提示目录权限问题

thatsitdeMacBook-Pro:~ thatsit$ brew link gdbm
Linking /usr/local/Cellar/gdbm/1.12...
Error: Could not symlink share/man/man3/gdbm.3
/usr/local/share/man/man3 is not writable.
thatsitdeMacBook-Pro:~ thatsit$

尝试sudo执行brew,提示已经不再支持以root权限执行

thatsitdeMacBook-Pro:~ thatsit$ sudo brew link gdbm
Password:
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
thatsitdeMacBook-Pro:~ thatsit$

确认目录权限并调整

thatsitdeMacBook-Pro:~ thatsit$ ll /usr/local/share/man/man3/
total 240
-rw-rw-r-- 1 root wheel 25111 1 12 2014 cdt.3
-rw-rw-r-- 1 root wheel 27894 1 12 2014 cgraph.3
-rw-rw-r-- 1 root wheel 1762 1 12 2014 expr.3
-rw-rw-r-- 1 root wheel 2103 1 12 2014 gvc.3
-rw-rw-r-- 1 root wheel 2966 1 12 2014 gvpr.3
-rw-rw-r-- 1 root wheel 9628 1 12 2014 pack.3
-rw-rw-r-- 1 root wheel 5386 1 12 2014 pathplan.3
-rw-rw-r-- 1 root wheel 15026 1 12 2014 tcldot.3tcl
-rw-rw-r-- 1 root wheel 7109 1 12 2014 tkspline.3tk
-rw-rw-r-- 1 root wheel 8157 1 12 2014 xdot.3
thatsitdeMacBook-Pro:~ thatsit$
thatsitdeMacBook-Pro:~ thatsit$ sudo chown -R thatsit /usr/local/share/man/man3/
thatsitdeMacBook-Pro:~ thatsit$

再次执行,OK

thatsitdeMacBook-Pro:~ thatsit$ brew link gdbm
Linking /usr/local/Cellar/gdbm/1.12... 12 symlinks created
thatsitdeMacBook-Pro:~ thatsit$
thatsitdeMacBook-Pro:~ thatsit$ brew install python3
==> Installing dependencies for python3: xz
==> Installing python3 dependency: xz
==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.2.el_capitan.bottle.tar.gz
######################################################################## 100.0%
==> Pouring xz-5.2.2.el_capitan.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink lib/pkgconfig/liblzma.pc
/usr/local/lib/pkgconfig is not writable.

You can try again using:
brew link xz
==> Summary
?? /usr/local/Cellar/xz/5.2.2: 91 files, 1.4M
==> Installing python3
==> Downloading https://homebrew.bintray.com/bottles/python3-3.5.2_3.el_capitan.bottle.tar.gz
######################################################################## 100.0%j
==> Pouring python3-3.5.2_3.el_capitan.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink lib/pkgconfig/python-3.5.pc
/usr/local/lib/pkgconfig is not writable.

You can try again using:
brew link python3
==> Using the sandbox
==> /usr/local/Cellar/python3/3.5.2_3/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python3/3.5.2_3/bin --install-lib=/usr/local/lib/python3.5/site-packages --single-version-externally-managed --record=installed.txt
==> /usr/local/Cellar/python3/3.5.2_3/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python3/3.5.2_3/bin --install-lib=/usr/local/lib/python3.5/site-packages --single-version-externally-managed --record=installed.txt
==> /usr/local/Cellar/python3/3.5.2_3/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/usr/local/Cellar/python3/3.5.2_3/bin --install-lib=/usr/local/lib/python3.5/site-packages --single-version-externally-managed --record=installed.txt
==> Caveats
Pip, setuptools, and wheel have been installed. To update them
pip3 install --upgrade pip setuptools wheel

You can install Python packages with
pip3 install <package>

They will install into the site-package directory
/usr/local/lib/python3.5/site-packages

See: https://github.com/Homebrew/brew/blob/master/docs/Homebrew-and-Python.md

.app bundles were installed.
Run `brew linkapps python3` to symlink these to /Applications.
==> Summary
?? /usr/local/Cellar/python3/3.5.2_3: 3,498 files, 53.3M
thatsitdeMacBook-Pro:~ thatsit$

添加python3环境变量

thatsitdeMacBook-Pro:~ thatsit$ tail -1 /etc/profile
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Cellar/python3/3.5.2_3/bin
thatsitdeMacBook-Pro:~ thatsit$

测试

thatsitdeMacBook-Pro:bin thatsit$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
thatsitdeMacBook-Pro:bin thatsit$ python3
Python 3.5.2 (default, Oct 11 2016, 05:05:28)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
thatsitdeMacBook-Pro:bin thatsit$

  

DONE

时间: 2024-08-06 20:08:23

Mac打造python2 python3开发环境的相关文章

Vagrant 打造跨平台的开发环境

两个项目开发下来,因团队环境不一样,整合修bug成为了一件苦差事.虽然后来搭建了一台测试服务器,但是有时候受网络原因,还是不能连接到测试服务器上.因团队成员能力和习惯都不一样,有的使用windows,有的钟爱ubuntu环境开发,虽然可以各自搭建虚拟机,但是涉及到环境工具插件等安装也会导致环境出现差别.这样的问题明显跟团队协作背道而驰,不符合程序员的逻辑,肯定有相应的办法解决.这办法就是Vagrant,而且vagrant是open source的. step1:安装虚拟机支持环境:Virtura

Mac配置React Native开发环境

一直觉得学习一样东西,不动手怎么也学不会,就像学习swift,看了视频没有动手操作,记住的也就那么点,自己写出东西不是这里有问题就是那里出错. 所以,以后学习自己要多动手. 现在我的学习任务就是: 提高自己的iOS代码专业能力,掌握Swift3.0,顺便学习学习React Native. 学习一门语言当然少不了硬件和软件设备啦,不然怎么学习...嘿嘿,对吧!!!! 下面记录下自己配置React Native开发环境: 1> 安装brew: 打开终端,输入:   /usr/bin/ruby -e

Mac下搭建php开发环境[翻译]

原英文链接:http://www.codeweblog.com/mac-os-x-to-configure-apache-php-mysql/ Mac OS X 内置了Apache 和 PHP,这样使用起来非常方便.本文以Mac OS X 10.6.3为例.主要内容包括: 启动Apache 运行PHP 安装MySQL 使用phpMyAdmin 配置PHP的MCrypt扩展库 设置虚拟主机 启动Apache 有两种方法: 打开"系统设置偏好(System Preferences)" -&

Mac系统cocos2dx + android 开发环境配置

Mac系统cocos2dx + android 开发环境配置 /****************************************************** 这遍文章主要转载自:http://www.cnblogs.com/wt616/p/3758828.html(这位大哥真的很牛,谢谢!) 然后,文章中又加入了一些自己的理解以及在实际操作过程中遇到问题的解决办法.而这些办法也是来自于伟大 的网友,但由于搜索的比较多,很多出处地址都没有记录好,抱歉,若你们看到,告诉我,我再加上地

mac 配置Python集成开发环境

mac 配置Python集成开发环境(Eclipse +Python+Pydev) 1.下载Mac版64位的Eclipse. 进入到Eclipse官方网站的下载页面(http://www.eclipse.org/downloads/),我选择了下图所示的软件包, 浏览器在下载过程中使用的超链接 http://ftp.daum.net/eclipse//technology/epp/downloads/release/mars/R/eclipse-jee-mars-R-macosx-cocoa-x

mac 下搭建 Android 开发环境

因工作需要,要在mac 下搭建 Android 开发环境.谷歌.度娘了好久,没有找个一个完整又系统的方法,很是苦恼.最终,皇天不负有心人,找到了下面这篇文档,特此记录.也为有这方面需求的朋友提供个方便. 首先我们需要知道开发安卓的环境由以下几个组件组成:Java虚拟机JDK.Eclipse.Eclipse插件ADT(Android Developer Tool)和Android开发包SDK.下面就和大家一起学习如何来快速的,适合新手的搭建方式吧! 方法/步骤 因为系统自带jdk,所以就不用在下载

mac下安装c++开发环境

mac下安装c++开发环境 1 注册apple id 按照apple注册步骤注册apple id,我注册时遇到如下问题 apple store完成创建apple id步骤中,选择付款方式和账单地址后,总会提示"如需帮助,请联系itune支持",进而导致apple store无法下载软件 解决办法为: https://support.apple.com/zh-cn/itunes,在该页面提交问题描述给apple技术支持,描述问题及apple id,三个工作日左右给出答复. 2 安装xco

windows和linux下 Python2,Python3 的环境及安装

目录 windows和linux下 Python2,Python3 的环境及安装 window下安装 一. 手动安装 二. pip安装 linux下 安装 更新Python 笔者有话 windows和linux下 Python2,Python3 的环境及安装 window下安装 1.下载安装包 https://www.python.org/downloads/ 2.安装 默认安装路径:C:\python27 3.配置环境变量 [右键计算机]-->[属性]-->[高级系统设置]-->[高级

打造自己的开发环境

前言:大多数时候自己都是在写C++程序,本文记录一下打造自己的开发环境的过程,方便以后查阅,免得某些东西记不起来的时候还要去百度找.打造的开发环境是代码在Linux服务器上(构建)编译-链接-运行,在windows环境编辑代码. 用到的工具: VMware-workstation : 虚拟机 ubuntu-16.04.5-server :Linux服务器版 MobaXterm : SSH连接工具 sublime : 文本编辑器 Linux上需要安装的工具:openssh-server  samb