1. Why Do We Need to Change VS Code’s Default Terminal?
For users who develop Python with VS Code, the terminal is an important bridge connecting code and the runtime environment. By default, VS Code uses PowerShell as the terminal for running Python files, but this default setting can cause troubles in some scenarios. The most typical problem is the compatibility issue with Anaconda virtual environments — many developers use Anaconda to create independent Python virtual environments and activate them via the conda activate env-namecommand to achieve dependency isolation for different projects. However, this command often fails to execute normally in the PowerShell terminal, which directly leads to the failure of virtual environment activation and affects subsequent development work.
On the other hand, the Command Prompt (CMD) terminal is fully compatible with the `conda activate` command and can activate Anaconda virtual environments smoothly. Therefore, switching the default terminal for running Python files in VS Code from PowerShell to CMD has become a necessary operation for many Python developers.
2. Method 1: Quickly Change the Default Terminal via Command Palette
The Command Palette is an efficient function call entry in VS Code, through which you can quickly switch the default terminal. The detailed steps are as follows:
- Open VS Code and make sure the Python project or file you need to run is already open.
- Click the `View` option in the top menu bar, then choose the `Command Palette` in the drop-down menu, or directly use the shortcut `Ctrl+Shift+P` to open the Command Palette.
- Enter the keyword `Terminal` in the input box of the Command Palette, and the system will automatically filter related commands.
- Find and click the option `Terminal: Select Default Profile`.
- Select the `Command Prompt` option from the pop-up list of terminal types.
- Close all terminal windows already open in VS Code to ensure the settings take effect.
- Right-click the Python source code file, select `Run Python`-`Run Python File in Terminal`, and the terminal opened at this time will automatically switch to CMD.
- Click the drop-down arrow in the upper right corner of the terminal, and you can see that `Default` is marked behind `Command Prompt`, indicating that the default terminal has been successfully modified.
3. Method 2: Precisely Configure the Default Terminal via Settings Page
If you find the operation of the Command Palette not intuitive enough, you can also configure the default terminal through the VS Code Settings page. The steps are as follows:
- Open VS Code, find the gear-shaped `Settings` button in the lower left corner, and click it.
- Select the `Settings` option from the pop-up menu to enter the VS Code Settings page.
- Enter the configuration item name `terminal.integrated.defaultProfile.windows` in the search box at the top of the Settings page.
- The search results will display the corresponding configuration item, and there is a drop-down list on the right side of the configuration item. Click to expand the list.
- Select the terminal type you need to set from the drop-down list, such as `Command Prompt` or `PowerShell`.
- After selection, close the Settings page directly without additional saving, as VS Code will save the configuration automatically.
- Right-click the Python source code file, select `Run Python`-`Run Python File in Terminal`, and verify whether the default terminal has been switched successfully.
- Similarly, you can check the status of the current default terminal through the drop-down arrow in the upper right corner of the terminal.
4. Summary: Choose Either Method to Solve Terminal Compatibility Issues Easily
Both methods above can realize the switching of the VS Code default terminal, and you can choose the suitable way according to your own operation habits. Method 1 is operated through the Command Palette with concise steps, suitable for users pursuing efficiency; Method 2 is configured through the Settings page, which is intuitive and easy to understand, suitable for novice users.
After modification, both methods can solve the incompatibility problem between PowerShell and conda virtual environments, making the Python development process smoother. Mastering this small skill can help you avoid pitfalls in development and improve development efficiency.
5. Demo Video
You can watch the following demo video by select the subtitle to your preferred subtitle language.