简体   繁体   English

即使在激活环境后,VSCode Mac 仍显示不正确的解释器

[英]VSCode Mac shows incorrect interpreter even after activation of environment

Problem问题

I am new to VSCode so I was trying to use the existing conda environments as part of my project in VSCode.我是 VSCode 的新手,所以我试图将现有的 conda 环境用作我在 VSCode 中的项目的一部分。 I was able to use Shift+Cmd+P to select the relevant interpreter我能够使用Shift+Cmd+P来选择相关的解释器

(in this case named mlops , as visible at the bottom right of the image below) (在本例中名为mlops ,如下图右下方所示)

在此处输入图像描述

I was able to test that after selecting the interpreter, my code was actually using this, as displayed in the left side terminal window using the code below -在选择解释器后,我能够测试,我的代码实际上正在使用它,如左侧终端窗口中所示,使用下面的代码 -

import sys
print("Interpreter:")
print(sys.executable)

Finally, I then went to another bash terminal (right side) and activated the conda environment.最后,我然后去了另一个 bash 终端(右侧)并激活了 conda 环境。 But, when I checked which python it still points to the wrong interpreter.但是,当我检查which python时,它仍然指向错误的解释器。


Attempts尝试

I have gone through a large number of questions and solutions to solve this issue and most of them point to adding terminal.integrated.inheritEnv as False in the settings.json我已经经历了大量的问题和解决方案来解决这个问题,其中大多数指向在settings.json中将terminal.integrated.inheritEnv添加为False

But it doesn't seem to fix the issue.但这似乎无法解决问题。

My question is 2 fold:我的问题是2折:

  1. Why is this happening and is this only a mac/Linux issue?为什么会发生这种情况,这只是一个 mac/Linux 问题吗?
  2. How do I fix this, in general, for my current and future projects?一般来说,我如何为我当前和未来的项目解决这个问题?

This is a common problem.这是一个常见的问题。 Switching between different environments will lead to confusion in the environment.在不同环境之间切换会导致环境混乱。

What we need to do is to deactivate all environments and then reactivating conda environment .我们需要做的是停用所有环境,然后重新激活 conda environment

You can refer to this issue which is the same to your problem for more information.您可以参考与您的问题相同的此问题以获取更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的 VSCode 解释器在 Mac 上不起作用? - Why my VSCode's interpreter is not working in Mac? 在vscode中为notebook配置Python解释器与conda环境的解释器相同 - Configure Python interpreter for notebook in vscode to be the same as the interpreter for a conda environment Python 解释器(VScode)“激活”一个 conda 环境,但环境没有改变 - Python interpreter (VScode) "activates" a conda environment, but the environment doesn't change 诗歌环境激活后自动运行脚本 - automatically run script after poetry environment activation 即使在编辑 python.analysis.extraPaths 之后,VSCode 中的 Pylance 仍然显示 reportMissingImports - Pylance in VSCode still shows reportMissingImports even after editing python.analysis.extraPaths App Engine本地环境显示不正确的数据 - App Engine local environment shows incorrect data VSCode 未检测到 Mac OS 上的 Python 虚拟环境 - VSCode not detecting Python Virtual Environment on Mac OS 为什么conda在激活另一个环境后重新定义基本环境? - Why conda redefines base environment after activation of another environment? 安装 python 后的 VSCode 在选择解释器时显示错误 - VSCode after installing python showing error in selecting interpreter 在virtualenv激活之后,哪个python`仍然显示非virtualenv路径 - `which python` after virtualenv activation still shows the non virtualenv path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM