`
angelbill3
  • 浏览: 253007 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
社区版块
存档分类
最新评论

Mac OX系统下Python 3.x环境搭建

阅读更多
1. 在MAC OS上安装Python v3.6:

Mac OS X系统在版本10.8后会预安装Python v2.7,查看当前预安装版本命令:python -V
这个版本不建议删除,详见官方文档:https://docs.python.org/3/using/mac.html
引用
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.

安装包官方下载:https://www.python.org/downloads/mac-osx/

用安装包安装或是用brew工具都可以~

顺便,下载版本比如Python 3.6.0rc1,其中的rc=Release Candidate,含义是"发布候选版",它不是最终的版本,而是最终版(RTM=Release To Manufacture)之前的最后一个版本。(摘自百度)

安装好v3.6后,对于Mac中多版本的python,使用不同的命令,如下:
>python -V
Python 2.7.5


>python3 -V
Python 3.6.0


2. 安装IDE
很多IDE可供选择,stack overflow上有总结,戳: http://stackoverflow.com/questions/81584/what-ide-to-use-for-python

由图看出不同的IDE的功能介绍:


我选择的是eclipse的Pydev,官网: http://www.pydev.org,下载介绍: http://www.pydev.org/download.html

插件和Eclipse是有版本匹配的,比如:
Eclipse 4.5, Java 8: PyDev 5.2.0
Eclipse 3.8, Java 7: PyDev 4.5.5
Eclipse 3.x, Java 6: PyDev 2.8.2

最新版本的eclipse 插件site地址是: http://www.pydev.org/updates
其它版本查找: http://www.pydev.org/update_sites/

我用的是经典版本Luna(4.4.2),所以准备安装5.1版本。
具体步骤: Eclipse - Help - Install New Software - [add]
Name: (自己输一个)比如: pydev - 5.1.2
Site: (按需选版本)http://www.pydev.org/update_sites/5.1.2

如果遇到错误:
An error occurred while collecting items to be installed
session context was:(profile=epp.package.jee, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).


解决方法: 修改eclipse.ini的jdk版本,我的默认JDK是1.8,而我的eclipse版本过低(通过添加-vm参数)。
-vm
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/../jre/lib/server/libjvm.dylib


安装好后重启eclipse,菜单Preferences下会多一项PyDev。

最后一项,配置Python interpreter:
Preferences - PyDev - Interpreters - Python Interpreter,点击:Advanced Auto-Config选出想要的版本。

若需要自己add,官方上的文档讲的非常详细,具体戳: http://www.pydev.org/manual_101_interpreter.html

3. 写个Hello world验证下吧
为了方便,添加新的视图,window - Open Perspective - PyDev

新建Python Project:
if __name__ == '__main__':
    print('hello world!');


输出: hello world!

完毕!
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics