【问题标题】:Python path is different between VS Code terminal and default terminalVS Code 终端和默认终端之间的 Python 路径不同
【发布时间】:2021-05-02 13:32:00
【问题描述】:

我在 MacOS 默认终端和 VS Code 集成终端中都使用了 conda,但是它们使用不同的 Python,这真的很奇怪,我不知道如何保持它们相同。

VS Code 终端:

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 默认终端:

▶ 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

【问题讨论】:

  • 你在VS Code和系统中使用的终端是什么? (Cmd 或 PowerShell 或 conda 终端)。你想使用哪个环境?请检查终端是否成功激活所需的conda环境。
  • @JillCheng 我已经把这些信息放在上面了。

标签: python visual-studio-code terminal


【解决方案1】:

您可以在 settings.json 文件中检查此键的值是什么

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

您也可以查看post

【讨论】:

  • VS代码编辑器使用与masos默认终端相同的python路径,易于配置。这里我尝试解决集成终端的问题。
  • 啊好吧对不起!我用一个有用的链接更新了我的答案。
  • 谢谢,我查看了这篇文章,我的问题应该与默认 shell 无关,因为您可以看到我在上面报告了 $SHELL 的结果。
【解决方案2】:

根据您提供的信息,我测试了您使用的命令。

我在VS Code里面的cmd终端测试的结果是:

我在VS Code外的cmd终端中测试的结果是:

它们类似于 MacOS 默认终端的结果。在VS Code中,它使用的终端是从系统自带的终端集成而来的,所以在使用上基本相同。

建议您在 VS Code 终端上查看基础 conda 环境是否激活。 (例如,使用命令“python --version”来检查是否是conda中的python。)

参考:conda environment in VS Code

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-17
    • 2020-04-09
    • 1970-01-01
    • 2022-01-06
    • 2017-09-04
    • 2021-11-01
    • 2017-08-18
    • 1970-01-01
    相关资源
    最近更新 更多