无论我做什么,VSCode Python 版本在集成终端中默认为 2.7 [英] VSCode Python version defaults to 2.7 in the integrated terminal no matter what I do

查看:47
本文介绍了无论我做什么,VSCode Python 版本在集成终端中默认为 2.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MacOS Mojave 10.14.6 上运行 VSCode 1.36.0.

当我在 VSCode 中使用集成终端并运行 Python 时,它总是从 MacOS 上的 /usr/bin/python 运行 Python 2.7,而不是默认的 anaconda Python.如果我在系统终端中做同样的事情,一切都很好.

我查看了这两个相关问题的答案:

为什么 macOS Visual Studio 代码使用错误的 Python口译员?

如何在 Visual Studio 中更改 python 版本代码?

我没有运行代码运行器扩展.我已将 python.pythonPath 设置更新为指向 Anaconda Python,但无论我做什么,集成终端中的 which python 都返回 /usr/bin/蟒蛇.使用 conda activate myenv 选择不同的 conda 环境也没有任何作用.

以前从未遇到过这个问题.

解决方案

通过执行 echo $SHELL 获取默认终端的 shell 路径这应该输出类似 /bin/bash

现在检查 VSCode 集成终端是否指向同一个 shell,如果不是,请将 VSCode 的集成 shell 设置为您的终端之一.

编辑(提供完整的解决方案):

vsCode 将每个新 shell 作为登录 shell 运行因此,如果您在 .bashrc 中设置 Anaconda 路径,则不会在集成 shell 中设置.如果是这种情况,您可以设置 "terminal.integrated.shellArgs.osx": [] 以强制 vsCode 运行非登录 shell 并加载 .bashrc

I'm running VSCode 1.36.0 on MacOS Mojave 10.14.6.

When I use the integrated terminal in VSCode and run Python it always runs Python 2.7 from /usr/bin/python on MacOS instead of the default anaconda Python. If I do the same in the system terminal everything is fine.

I've looked at the answers in these two related questions:

Why Is macOS Visual Studio Code Using Wrong Python Interpreter?

How can I change python version in Visual Studio Code?

I'm not running the code-runner extension. I've updated the python.pythonPath setting to point to Anaconda Python and yet no matter what I do, which python in the integrated terminal returns /usr/bin/python. Selecting a different conda environment with conda activate myenv doesn't do anything either.

Haven't experienced this issue before.

解决方案

Get the shell path of your default terminal by executing echo $SHELL this should output something like /bin/bash

now check if the VSCode integrated Terminal points to the same shell and if not, set the integrated shell of VSCode to the one of your terminal.

Edit (to provide the full solution):

vsCode runs every new shell as login shell so if you set the Anaconda Path in .bashrc it will not be set in the integrated shell. If this is the case, you can set "terminal.integrated.shellArgs.osx": [] to force vsCode to run a non Login shell and load .bashrc

这篇关于无论我做什么,VSCode Python 版本在集成终端中默认为 2.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆