python - 在 macOS 上将 Visual Studio Code 与 Miniconda 结合使用

标签 python visual-studio-code vscode-settings miniconda

在我的 Mac 上,我使用 Miniconda 安装了 Python我还使用 conda 安装了各种 Python 包。在 Mac 终端应用程序中,我的 base conda 环境处于事件状态,当我运行 Python 时,它正确地使用了 Miniconda 版本的 Python,如下所示:

python in Mac terminal

在 Visual Studio Code (VSCode) 中,我使用 Python Interpreter 设置选择了 Python 的 Miniconda 版本。窗口底部显示了正确的 Python 版本和 conda 环境:

python interpreter

但是,当我在 VSCode 中使用内置终端时,它仍然使用 macOS Python,即使它显示 base conda 环境处于事件状态:

vscode terminal python

我在 VSCode 中使用 Python、One Dark Pro 和 Jupyter 扩展。此外,VSCode 终端和 Mac 终端应用程序中的 $PATH 返回以下内容:

# VSCode terminal
base ❯ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin:/Users/gavinw/miniconda3/bin:/Users/gavinw/miniconda3/condabin
# Mac terminal app
base ❯ echo $PATH
/Users/gavinw/miniconda3/bin:/Users/gavinw/miniconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/Library/Apple/usr/bin

如何配置 Visual Studio Code 终端以使用 Python 的 Miniconda 版本?

最佳答案

选择conda自带的Python后,VSCode左下角会显示Python解释器,然后使用快捷键Ctrl+Shift+`打开一个新的VSCode终端,(或者点击“Terminal”, “新终端”)会自动进入选择的环境并自动激活。

enter image description here

关于python - 在 macOS 上将 Visual Studio Code 与 Miniconda 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65317721/

相关文章:

python - 当mysql查询包含python中的占位符时如何搜索武术比赛?

python - 如何在 Django 中基于另一个模型的实例创建模型,但经过过滤

tabs - 如何让 VS Code 编辑器选项卡在左侧关闭?

java - 任何人都可以做到这一点吗?如何将 VS-Code 多个扩展从一种语言特定扩展切换到另一种语言特定扩展?

visual-studio-code - 如何在 vscode 中重新映射 `down` 快速打开菜单?

visual-studio-code - VS Code - 如何在命令面板中通过完整路径打开文件?

python - "import datetime"对比"from datetime import datetime"

Python 'astype' 不工作

visual-studio-code - VSCode自定义窗口边框

visual-studio-code - 如何使用环境变量为 pytest 配置 VS 代码