If you are using the CLI, (command line interface), that is, the text terminal in Ubuntu Linux, be sure you are actually running Python interpreter within your CLI.
From the command prompt $, type "python" or perhaps "python3". That should get you a python prompt that looks like this: >>>. That will be where you enter your commands into the python interpreter.
From the python prompt >>> you can type your simple commands.
If you are saving these to a program/script as a .py file, then to run the script you would need to type "python ./hello.py", in order to recruit the python interpreter to run the script.
If you are using a specific development environment (IDE), like VS Code, Eclipe, or PyCharm, or some other, let us know. These are special programs for writing code where you type and save your file in a window within the program. These have their own processes for running the program from the IDE. Most will have a play button somewhere to run the script and give output in a separate pane, e.g., near the bottom of the window as in VS Code.
Answer from Eric on askubuntu.comSo I have a file named main.py, in it there is just a basic print("Hello world")
I tried running it but it shows no output, both in vsc code runner and by running through a terminal. I thought something was wrong with my code, but it ran in some online ide. How do I fix my python? when i did py --version it shows Python 3.12.3. Ive added it to the path, i really dont know what to do.
Thanks for help:)
If you are using the CLI, (command line interface), that is, the text terminal in Ubuntu Linux, be sure you are actually running Python interpreter within your CLI.
From the command prompt $, type "python" or perhaps "python3". That should get you a python prompt that looks like this: >>>. That will be where you enter your commands into the python interpreter.
From the python prompt >>> you can type your simple commands.
If you are saving these to a program/script as a .py file, then to run the script you would need to type "python ./hello.py", in order to recruit the python interpreter to run the script.
If you are using a specific development environment (IDE), like VS Code, Eclipe, or PyCharm, or some other, let us know. These are special programs for writing code where you type and save your file in a window within the program. These have their own processes for running the program from the IDE. Most will have a play button somewhere to run the script and give output in a separate pane, e.g., near the bottom of the window as in VS Code.
Thanks everyone and apologies the answer was simple. I had not yet switched on autosave in vscode it now works perfectly.
Videos
Your program does not output anything because you are never calling your function.
This will do what you expect:
def GetNum():
x = int(input("Input something: "))
while (x > 0):
x = int(input("Input something: "))
print(x)
GetNum()
I removed the function argument Text, added a call to the GetNum function and added type conversions from str to int for both input() calls.
You haven't called your GetNum function.
You need to add the following to the bottom of your script:
GetNum(None)
Text is not used, so None is a null object.
You may want to read up on defining functions, function arguments and calling functions, which is out-of-scope for StackOverflow - See http://www.tutorialspoint.com/python/python_functions.htm
I am very new to python so it is probably a very easy fix but when I try to run a very simple code such as print("Hello World") there is no output in the terminal. Not even an error message. I have already checked and the latest version of python is installed on my PC. I made a file yesterday off of the notepad browser titled "Helloworld.py" and it worked perfectley fine. I open the the file "Helloworld.py in visual studio world today but no output is occuring? Can someone please help me?
Using the Python Extension Run/Debug commands
Notes
I recommend reviewing the official Visual Studio Code Python documentation and tutorial. That provides several of the basics, with running and debugging the "official" way.
There are multiple ways to configure built-in launches:
- When running or debugging Python in VS Code, there are a few options that you can change in your "launch.json" file. See this answer for more details.
Run or Debug with the built-in Python extension commands
You can run or debug using the "triangle" icon and dropdown in the upper right of your editor window, when the editor window is focused on a python script file (i.e. typically a file named *.py).

You may need to setup a run/debug configuration to use this (see below), or it may automatically step you through creating one.
The output will normally go to a new "Python" terminal in the "terminal" window (Ctrl-`, to open it). See this answer for how to change that behavior.
Setting up a run/debug configuration
Easy option:
- Use the menu item **
Run/Add Configuration, and follow the prompts at the top of the VS Code window. - Some of the additional details are shown below.
More involved option:
- Click the run/debug icon on the left vertical icon toolbar.
- The window says "RUN AND DEBUG" at the top, with a drop-down that shows "No Configurations" for a given folder or workspace until you set this up.
- The gear to the right of the dropdown will have a red dot if you need to configure this:

Updated Image (1/2022) - Changed from just 'Debug' to 'Run and Debug':

- Click the gear icon (or in the menu, use Run/Open Configurations), and in the middle at the top, Visual Studio Code will open a window titled "Select a debug configuration".
- The available options will depend on exactly how you have Visual Studio Code setup and configured
- There should at least be a "Python File" option with the Python extension installed. Select it.

Now your debug configuration box on the top left of the debug pane should say "Python: Current File":

Visual Studio Code will add a file to your current workspace or working folder called .vscode/launch.json, and opened it for edit.
Simplest Answer: Run the file directly in a terminal
Open a terminal in VS Code (View/Terminal in menu or Ctrl-`, which is the "Ctrl" key and the "Grave" or "Tick-mark" key, normally at the top left of keyboard above tab).
- This will open the terminal to the root of the folder VS Code has open (the one that shows up in the Explorer sidebar - Ctrl-Shift-E to see).
Run the python script in the current directory with a simple
python my_script.pycommand.- If the script is in another directory than the root of the current workspace or folder you opened the terminal in, you will need to change to that directory (using
cdcommands, etc.), or add the absolute or relative folder path to the name of the script.
- If the script is in another directory than the root of the current workspace or folder you opened the terminal in, you will need to change to that directory (using
The output will show up in the same terminal.
Notes
- You must have a python executable on your path, be in an active virtual environment, or give the full path to the python executable.
- Your
pythoncommand may bepython2orpython3on some installs (usually linux), and can be justpyfor the Python Launcher (auto-installs with typical Python for Windows installs). - This option will not use any 'launch.json' configurations, and cannot be easily used to debug with.
- You can configure the default terminal that is used, such as Git Bash, CMD, or Powershell (on Windows). You can also open additional terminal windows of any configured type using the "+" icon and it's dropdown, in the terminal window.
By the way, U said after you run "pip --version" nothing was displayed, I think this means you didn't install python correctly, pip should be installed automatically after you install Python. Just remind, make sure set the right Python path to your computer system path, set the "path" variable to the correct python istalled path.
In my opinion, you should uninstall python, and reinstall again.Any problem please let me know.
I think you may need a virtual machine, take a look about Vagrant.
You can set up a whole python environment on Linux and use the Vagrant package on Windows.
It's an amazing tool.
Try running the following in the Ipython console.
%config InteractiveShell.ast_node_interactivity='last_expr'
This is the setting description:
ZMQInteractiveShell.ast_node_interactivity=<Enum>
Current: 'last_expr'
Choices: ['all', 'last', 'last_expr', 'none', 'last_expr_or_assign']
'all', 'last', 'last_expr' or 'none', 'last_expr_or_assign' specifying which
nodes should be run interactively (displaying output from expressions).
You need to highlight what you want to run.
Then run/execute the current line/s by either pressing F9, or the Run selection or current line button on the Run toolbar(the black one).
It will then show output without needing to use print
