You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode中PS/CMD终端不打开当前工作目录及Python运行问题求助

Hey there, let's work through these VSCode terminal and Python issues together—they're pretty common, so we'll get you sorted out in no time!

Fixes for VSCode Terminal (PS/CMD) Not Opening Current Working Directory

First, let's tackle the core issue of your terminal not landing in your workspace folder. Try these steps one by one:

  • Check your terminal working directory setting
    Open VSCode settings (press Ctrl+,), search for terminal.integrated.cwd, and make sure it's set to ${workspaceFolder}. This variable tells VSCode to launch the terminal directly in your open workspace directory. If it was changed to a hardcoded path, switch it back to this dynamic variable.

  • Reset your default terminal profile
    Sometimes corrupted profile settings throw this off. Press Ctrl+Shift+P, type Terminal: Select Default Profile, and reselect either PowerShell or Command Prompt. Then run Terminal: Create New Integrated Terminal from the command palette to test if it opens in the right directory.

  • Run VSCode as Administrator
    Permissions can block VSCode from accessing certain directories. Right-click the VSCode icon, select "Run as administrator", then open your workspace and launch a new terminal. This often fixes access-related directory issues.

  • Verify system PATH variables
    Ensure your system's PATH includes the default locations for CMD and PowerShell:

    • CMD path: C:\Windows\System32\cmd.exe
    • PowerShell path: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
      If either is missing, add them to your system PATH via Windows Settings > System > About > Advanced system settings > Environment Variables.
Extra Fixes for Python Not Running in the Working Directory

Once your terminal is opening in the correct folder, if Python still won't run there, try these tweaks:

  • Confirm the terminal is in the right directory
    In PowerShell, run pwd; in CMD, run cd to check the current path. It should match your workspace folder. If not, manually navigate there with cd path/to/your/workspace before running your script.

  • Select the correct Python interpreter
    Press Ctrl+Shift+P, type Python: Select Interpreter, and pick the Python version (or virtual environment) you want to use for your project. VSCode will then tie this interpreter to your terminal sessions, ensuring it can access your workspace files.

  • Check Python's accessibility in the terminal
    In the terminal, run python --version (or py --version for the Windows Python launcher). If it throws an error, your Python installation path might not be in the system PATH. Add your Python directory (e.g., C:\Python311) and its Scripts subfolder to the system PATH, then restart VSCode.

  • Move your project to a non-restricted directory
    If your workspace is in a protected folder like C:\Program Files, Python might lack permission to read/write files. Move your project to a user directory (e.g., C:\Users\YourName\Projects) and try again.


内容的提问来源于stack exchange,提问作者Abhiseck

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:46:13