Problem
When running the following Python code in PyCharm:
for i in [1,2,3]:
print(i)
The output shows only:
Process finished with exit code 0
However, running the same code in Visual Studio Code produces the expected result, printing the numbers 1, 2, and 3.
Cause
The issue arises because the Run button in PyCharm re-executes the last used run configuration. This configuration might point to a different script (e.g., an empty main.py) instead of the currently visible file with the loop.
Resolution
To resolve the issue:
- Verify the file being executed. Check the first line in the Run window above the "Process finished with exit code 0" message. It will display the full command with the
.pyfile being run. Ensure it matches the file containing your loop. - Explicitly run your file:
- Right-click on your code in the editor.
- Select the "Run" option with your file's name.
- Confirm if the output shows the intended result.
- Try running the file with Debug mode (the icon next to the Run button). Debug uses a different channel for output, which can help confirm whether the script is running correctly.
If these steps do not resolve the issue, you may capture additional information by:
- Taking a screenshot of the whole PyCharm window with the Run panel visible.
- Collecting PyCharm IDE logs via: Help | Collect Logs and Diagnostic Data.
Provide these details to further investigate if needed.
Comments
0 comments
Please sign in to leave a comment.