Fixing the problem – Visual Studio Code is not showing the output of Python

Visual Studio Code is not showing the output of Python is a normal issue of python and visual studio code.

I will explain why this error takes place and how to fix it, while also trying to add other solutions that could solve the error.

Exploring the issue : Visual Studio Code is not showing the output of Python

This is a normal issue of python and visual studio code.

Please double check the top of this blog post so you can avoid mixing between different python issues.

Bellow is a number of tested solutions that I have tried and that have worked for me.

Solution 1 : use visual studio code for python the ‘correct way’

in visual studio code, go to the top of the screen and click terminal and open the terminal.

Now, before you execute any commands, you should know where you python script is located. If you are at the exact directory where your script is located. Then execute the command bellow, assuming your file is named mytest.py.

                                                                       #
python mytest.py
                                                                       #

If your file is located in a different directory. Then you should Cd into that directory then execute the script.

For example, if your current directory is

                                                                       #
C:\Users\hp\Desktop\sport-fans
                                                                       #

And your script is located in

                                                                       #
C:\Users\hp\Desktop\sport-fans\scripts
                                                                       #

Then you should cd into the directory using cd in the command line. Then run your command.

                                                                       #
cd C:\Users\hp\Desktop\sport-fans\scripts
                                                                       #

I hope this one fix solved your issue, try the solution bellow if this one did not do the trick.

Solution 2 : edit Settings.json in visual studio code

If you did not link python and visual studio during the installation, then its normal for visual studio to not return any output.

The solution is simple, open visual studio code and go to file then navigate to preference and then click and open Settings.json.

Add the code bellow to your Settings.json file

                                                                       #
"code-runner.executorMap":
{ "python": "\"C:\\Program Files\\Python310\\python.exe\""
                                                                       #

If you have a different python version replace it in the code above.

I hope the fix above fixed your problem, good luck with the scripts to come.

Summing-up

This is the end of this article, I hope this helped you solve the error. You can donate to our Kofi account if you feel generous but you do not Have to. Keep coding and learning, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/