macOS环境下体验python(20190111)
2019-01-11 本文已影响1人
watayouxiang
macOS环境下体验python(20190111)
作者操作系统 macOS Mojava 10.14,该系统自带 python 环境,版本号为 2.7
可通过
$ python -V
命令查询
pythoy官网下载并安装最新环境
Python>>> Downloads>>> Mac OS X 下载如下版本:
Python 3.7.2 - 2018-12-24
Download macOS 64-bit installer
安装完成后会出现以下两个APP

IDLE 是图形化界面,Python Launcher 可以配置python

用 IDLE.app 输出“hello world” (该编辑器关键字智能提示键为 tab
)
切换macOS默认使用的 Python 版本
macOS自带的python 2.7版本,但是如果想终端默认运行的是新下载的python 3.7.2版本可以这么做:
- 首先找到3.7.2版本python的路径
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
- 打开
~/.bash_profile
目录下的隐藏文件.bash_profile
,新增一行alias python="/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7"
- 重启 Terminal 生效
使用Anaconda玩耍python
Anaconda是学习Python很好的一个平台,所以可以用Anaconda-Navigator.app玩耍python
官网 https://www.anaconda.com/what-is-anaconda/
安装完成后会出现如下APP

Anaconda-Navigator.app 界面如下

Anaconda提供多种python编辑器,这里以Jupyter Notebook编辑器为例,点击运行

Jupyter Notebook 编辑器如下

- shitft+enter:运行py代码
- tab:关键字智能提示
- python语法学习网站推荐 W3C:https://www.w3cschool.cn/python3/python3-basic-syntax.html