Visual Studio Code终端无法激活Conda环境 [英] Visual Studio Code terminal doesn't activate Conda environment

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

问题描述

我阅读了有关类似问题的

但是当我在终端中执行 conda激活tom 后,即使执行 conda env列表,我也会得到输出:

 #conda环境:#基本* C:\ ProgramData \ Anaconda3汤姆C:\ Users \ yatin \ .conda \ envs \ tom 

代替:

 #conda环境:#基本C:\ ProgramData \ Anaconda3汤姆* C:\ Users \ yatin \ .conda \ envs \ tom 

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

运行python 的地方,但没有任何输出.

  import os导入系统os.path.dirname(sys.executable) 

给予

 'C:\\ Python38' 

解决方案

首先,打开Anaconda提示符( this Stack Overflow post on a similar issue, but the suggestions there don't seem to be working. I installed Visual Studio 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 Visual Studio Code 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

Instead 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?

where python runs, but it 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.

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

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