简体   繁体   English

Python VS Code 终端和默认终端之间的路径不同

[英]Python path is different between VS Code terminal and default terminal

I use conda in both MacOS default terminal and VS Code integrated terminal, but they use different Python, it's really strange and I don't know how to keep them same.我在 MacOS 默认终端和 VS Code 集成终端中都使用 conda,但是它们使用不同的 Python,这真的很奇怪,我不知道如何保持它们相同。

VS Code terminal: VS 代码终端:

Documents/GitHub/self-study  master ✗                                                                                                     23h17m ⚑  
▶ conda env list
# conda environments:
#
base                  *  /Users/wsx/Library/r-miniconda
d2l                      /Users/wsx/Library/r-miniconda/envs/d2l
r-reticulate             /Users/wsx/Library/r-miniconda/envs/r-reticulate
sigminer_sigprofiler     /Users/wsx/Library/r-miniconda/envs/sigminer_sigprofiler

(base) 
Documents/GitHub/self-study  master ✗                                                                                                     23h17m ⚑  
▶ which python
/usr/bin/python
(base) 
Documents/GitHub/self-study  master ✗                                                                                                     23h18m ⚑  
▶ which python3
/usr/local/bin/python3
Documents/GitHub/self-study  master ✗                                                                                                     23h18m ⚑  
▶ echo $SHELL
/bin/zsh

MacOS default terminal: MacOS 默认终端:

▶ conda env list
# conda environments:
#
base                  *  /Users/wsx/Library/r-miniconda
d2l                      /Users/wsx/Library/r-miniconda/envs/d2l
r-reticulate             /Users/wsx/Library/r-miniconda/envs/r-reticulate
sigminer_sigprofiler     /Users/wsx/Library/r-miniconda/envs/sigminer_sigprofiler

(base) 
~                                                                                                                      
▶ which python
/Users/wsx/Library/r-miniconda/bin/python
(base) 
~                                                                                                                      
▶ which python3
/Users/wsx/Library/r-miniconda/bin/python3
▶ echo $SHELL
/bin/zsh

You could check what's the value of this key in your settings.json file您可以在 settings.json 文件中检查此键的值是什么

"python.defaultInterpreterPath": "path-used-by-vscode"

You can check this post too.你也可以看看这个帖子

Based on the information you provided, I tested the commands you used.根据您提供的信息,我测试了您使用的命令。

The result of my test in the cmd terminal inside VS Code is:我在 VS Code 内的 cmd 终端中的测试结果是:

在此处输入图像描述

The result of my test in the cmd terminal outside VS Code is:我在 VS Code 之外的 cmd 终端中的测试结果是:

在此处输入图像描述

They are similar to the results of your MacOS default terminal.它们类似于 MacOS 默认终端的结果。 In VS Code, the terminal it uses is integrated from the system's own terminal, so they are basically the same in use.在 VS Code 中,它使用的终端是从系统自带的终端集成而来的,所以它们在使用上基本相同。

It is recommended that you check whether the base conda environment is activated on the VS Code terminal.建议您在 VS Code 终端上检查基础 conda 环境是否已激活。 (For example, use the command " python --version " to check if it is python from conda.) (例如,使用命令“ python --version ”来检查它是否是来自conda的python。)

在此处输入图像描述

Reference: conda environment in VS Code .参考: VS Code 中的 conda 环境

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM