
Python 开发指引
环境配置
Linux
国内镜像
/etc/pip.conf 添加一下内容
[global]
index-url=https://mirrors.163.com/pypi/simple
trusted-host=mirrors.163.com
macOS
brew install python # 默认已经开始安装 Python3
brew install ctags
pyenv
brew install pyenv
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/. bash_profile
# 升级
brew update && brew upgrade pyenv
pyenv install 3.7.9
pyenv global 3.7.9
组件管理
常用命令
常用路径
VS Code
启动 Code 后,安装微软发行的 Python 插件。按 Cmd + Shift + p,输入 Select Interpreter,选择 Python 解释器。
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
IDLE
交互式运行
命令行输入 IDLE 启动交互式命令行 Python Shell。
编辑代码
IDLE 有自己的菜单,选择 File > New File,可新建文件编辑代码:
# Receive input then store in name variable.
name = input("What's your name?\n")
print("Hi,", name)
按 F5 或菜单栏 Run > Run Module,运行当前文件: