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

Python解释器搭配TensorFlow在VS Code中无报错却无法运行求助

Troubleshooting VS Code Python Execution Issues (Works in CMD, Not in VS Code)

Hey there, sorry to hear you’ve spent three days wrestling with this setup only to hit this frustrating roadblock! Since your code runs perfectly in CMD but won’t execute at all in VS Code—even basic loops like while True—this almost always boils down to an environment mismatch or a VS Code configuration quirk. Let’s walk through the most likely fixes step by step:

1. Verify VS Code is using the correct Python interpreter

Your CMD environment works, so the first thing to check is whether VS Code is pointing to the same Python installation:

  • Look at the bottom-left corner of your VS Code window—you’ll see the current Python interpreter version. Click on it to open the interpreter selector.
  • Choose the exact Python 3.6 installation that you use in CMD. To confirm, run python --version and pip list in both VS Code’s terminal and your CMD window—they should show identical versions of Python, TensorFlow, and Keras.

2. Check your VS Code terminal profile

VS Code might be using a different terminal (like PowerShell) that doesn’t inherit your CMD environment variables:

  • Press Ctrl+Shift+P and search for Terminal: Select Default Profile.
  • Choose Command Prompt as your default terminal, then restart the terminal (click the trash icon in the terminal panel) and try running your code again.
  • If you’re using a virtual environment, make sure you activate it in the VS Code terminal first with venv\Scripts\activate (for Windows) before executing your script.

3. Inspect VS Code’s Python output logs

Sometimes errors don’t show up in the terminal but are logged in the output panel:

  • Press Ctrl+Shift+U to open the Output panel.
  • From the dropdown menu at the top of the panel, select Python. Look for any error messages related to interpreter loading or script execution—this can give you a clear clue about what’s broken.

4. Rule out plugin conflicts

Third-party VS Code plugins can sometimes interfere with Python execution:

  • Disable all plugins except the official Python extension by Microsoft.
  • Restart VS Code and test your script again. If it works, re-enable plugins one by one to find the culprit.

5. Reset VS Code Python settings (last resort)

If none of the above works, resetting your Python-related settings might fix hidden configuration issues:

  • Press Ctrl+Shift+P and search for Preferences: Open Settings (JSON).
  • Delete any lines related to python.pythonPath, python.venvPath, or other custom Python configurations.
  • Save the file, restart VS Code, and re-select your correct interpreter.

Since your CMD environment is fully functional, focusing on aligning VS Code with that environment should resolve the issue quickly. Good luck!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 00:12:55