本文介绍了VSCode终端无法激活conda环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了



但是当我执行 conda env list 即使在终端中执行 conda激活tom 之后,我仍然得到输出:

 #conda环境:

base * C:\ProgramData\Anaconda3
tom C:\Users\yatin\.conda\envs\tom

以下项的含义:

 #conda环境:

基本C:\ProgramData\Anaconda3
tom * C:\Users\yatin\.conda\envs\tom

当我尝试 python app.py 时,也不会导入未安装在base中的软件包。我该怎么办?



编辑:
运行python 但没有给出任何输出



此外,

  import os 
import sys
os.path.dirname(sys.executable)

给予

 'C:\\Python38'


解决方案

首先,打开Anaconda提示符(),然后输入:

  conda激活tom 

激活虚拟环境。
然后在此活动环境中打开Visual Studio代码,键入

  code 

它应该可以工作


I read this SO post on a similar issue but the suggestions there don't seem to be working. I installed VS Code on my windows machine and added the Python extension. Then I changed the python path for my project to C:\Users\yatin\.conda\envs\tom\python.exe. The .vscode/settings.json has this in it:

{
    "python.pythonPath": "C:\\Users\\yatin\\.conda\\envs\\tom\\python.exe"
}

The status bar in VSCode also shows:

But when I do conda env list even after doing conda activate tom in the terminal I get the output:

# conda environments:
#
base                  *  C:\ProgramData\Anaconda3
tom                      C:\Users\yatin\.conda\envs\tom

Intead of :

# conda environments:
#
base                     C:\ProgramData\Anaconda3
tom                   *  C:\Users\yatin\.conda\envs\tom

Also the packages not installed in base don't get imported when I try python app.py. What should I do?

Edit:where python runs but doesn't give any output

Also,

import os
import sys
os.path.dirname(sys.executable)

gives

'C:\\Python38'
解决方案

First, open the Anaconda prompt (How to access Anaconda command prompt in Windows 10 (64-bit)), and type:

conda activate tom

To activate your virtual environment.Then to open visual studio code in this active environment, type

code

And it should work

这篇关于VSCode终端无法激活conda环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-03 22:08