You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让VSCode正常使用通过Homebrew安装的Python3环境

VSCode 使用Homebrew Python3 环境配置步骤
  • 第一步 确认Homebrew Python路径有效性
    终端执行 brew list python3 | grep bin/python3,确认输出包含 /opt/homebrew/bin/python3,排除Homebrew安装失败的问题。
  • 第二步 调整Shell路径优先级
    当前which python3返回系统自带Python的核心原因是系统Python路径在环境变量中优先级高于Homebrew路径:
    1. 如果你使用Mac默认的zsh,执行open ~/.zshrc;使用bash则执行open ~/.bash_profile
    2. 在文件末尾添加以下内容:
    export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
    alias python3="/opt/homebrew/bin/python3"
    alias pip3="/opt/homebrew/bin/pip3"
    
    1. 保存文件后终端执行source ~/.zshrc(对应zsh)或source ~/.bash_profile(对应bash),重新执行which python3,确认输出为/opt/homebrew/bin/python3
  • 第三步 修正VSCode关联配置
    1. 打开对应项目后按Cmd+Shift+P调出命令面板,输入Python: Select Interpreter,手动输入/opt/homebrew/bin/python3完成选择,不要选择下拉列表中/Library路径下的Python版本
    2. 若使用Code Runner插件运行代码,需额外修改插件配置:打开设置搜索code-runner.executorMap,点击编辑json,将python对应的执行项修改为 "python": "/opt/homebrew/bin/python3 -u",
    3. 关闭VSCode当前已打开的所有终端,新开终端后执行python3 --version,确认版本号为Homebrew安装的3.9.9
  • 第四步 验证配置生效
    新建测试文件写入以下代码运行:
    import sys
    print(sys.executable)
    
    输出为/opt/homebrew/bin/python3即为配置成功。

内容的提问来源于stack exchange,提问作者함준하

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 08:54:00