【问题标题】:Why does vscode change directories before running a python file?为什么 vscode 在运行 python 文件之前会更改目录?
【发布时间】:2021-02-13 00:15:36
【问题描述】:

我在c:\github\housing\python 中有一个名为sync.py 的文件。当它在我的 VS Code 浏览器中打开时,我按 Ctrl F5 来执行它。当我这样做时,这就是我在 PowerShell 中看到的:

PS C:\github\housing\python> cd 'c:\github\twitter'; & 'C:\Users\azhad\Anaconda3\python.exe' 'c:\Users\azhad\.vscode\extensions\ms-python.python-2020.9.114305\pythonFiles\lib\python\debugpy\launcher' '52870' '--' 'c:\github\housing\python\sync.py'

为什么 VS Code 会更改为不同的目录?我注意到它似乎倾向于 twitter 文件夹,有没有我可以更改的默认设置来防止这种情况发生?

【问题讨论】:

    标签: python visual-studio-code


    【解决方案1】:

    通常情况下,在VSCode的终端“powershell”中执行python文件时,会在两个地方改变路径:

    1. "python.terminal.executeInFileDir": true, 设置在“settings.json”中。

    2. "cwd": "c:\\github\\twitter" 设置在“launch.json”中:

    建议您将“settings.json”和“launch.json”两个设置文件中的相关终端调试设置注释掉。另外,请尝试重新加载或重新打开 VSCode。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多