Python Forum
print does not open console in Linux Mint [Solved]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print does not open console in Linux Mint [Solved]
#1
Dear forum members,

I use Linux Mint Cinnamon 22.2 with Python 3.12.3
I have this simple script myscripy.py:

#!/usr/bin/python
print('Hello World!')
input('press enter to exit')
The file is executable.

I would like to run the scrip by double clicking, like I would in windows.
What I would like to happen if I double click the file:
a console opens and the text 'Hello World!' and 'press enter to exit' appears.

The program runs, but the console does not open, so I can't see the ouput of a print command.

I tried several things:

If I create a launcher with the command
$ python3 ./myscript.py
the console does not open.

If I run the script from the terminal
$ python3 ./myscript.py
the console opens with the text.

If I run the script from Visual Studio Code, the console also opens showing the text.

But I prefer to double click.

When I googled I found posts suggesting the st.out buffer needs to be flushed.
So I tried to use header
 #!/usr/bin/python -u
And I also tried to use
print('Hello World!', flush=True)
but still the console does not open.

Does anyone has a suggestion?
Reply
#2
Why should your code open a console?

run it with

gnome-terminal -- /path/to/myscript.py

or to start with double click, create a launcher
#!/bin/sh
gnome-terminal -- /path/to/myscript.py
Reply
#3
Or like this in bash: First write python3, then space, then your programme name. In my case, the file hello_world.py is in my cwd, general_things

Quote:peterr@peterr-Modern-15-B7M:~/PVE/general_things$ python3 hello_world.py
Hi cruel world!
Tycho_2025 likes this post
Reply
#4
(Oct-02-2025, 07:41 PM)Axel_Erfurt Wrote: Why should your code open a console?

run it with

gnome-terminal -- /path/to/myscript.py

or to start with double click, create a launcher
#!/bin/sh
gnome-terminal -- /path/to/myscript.py

Thank you Axel.

If the console or terminal does not open, I can't see the ouput of a print command.

Meanwhile I found a similar solution as you posted:
-right click on my_script.py
-open with --> other application
-in the open field give the command
gnome-terminal -e '/usr/bin/python3 %F'
-click 'Set as Default'
-click 'Ok'

In this way a .py file always runs AND you can see the output of a print command
(and without having to create a launcher or a separate bash file).
Gribouillis likes this post
Reply
#5
-e is deprecated

man gnome-terminal Wrote:--command, -e=COMMAND
Split the argument to this option into a program and arguments in the same way a shell would, and
execute the resulting command-line inside the terminal.

This option is deprecated. Instead, use -- to terminate the options, and put the program and
arguments to execute after it: for example, instead of gnome-terminal -e "python3 -q", prefer to use
gnome-terminal -- python3 -q.

Note that the COMMAND is not run via a shell: it is split into words and executed as a program. If
shell syntax is required, use the form gnome-terminal -- sh -c '...'.
Reply
#6
(Oct-03-2025, 03:59 PM)Axel_Erfurt Wrote: -e is deprecated

man gnome-terminal Wrote:--command, -e=COMMAND
Split the argument to this option into a program and arguments in the same way a shell would, and
execute the resulting command-line inside the terminal.

This option is deprecated. Instead, use -- to terminate the options, and put the program and
arguments to execute after it: for example, instead of gnome-terminal -e "python3 -q", prefer to use
gnome-terminal -- python3 -q.

Note that the COMMAND is not run via a shell: it is split into words and executed as a program. If
shell syntax is required, use the form gnome-terminal -- sh -c '...'.

Thank you, Axel, I also noticed the warning that -e is deprecated.
I will try your solution.
I also did some research and found:
gnome-terminal -- bash -c "/usr/bin/python3 %F; bash"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] Open file, and insert space in string? Winfried 7 2,523 May-28-2025, 07:56 AM
Last Post: Winfried
Question [SOLVED] Right way to open files with different encodings? Winfried 3 10,291 Jan-18-2025, 02:19 PM
Last Post: Winfried
  [SOLVED] [Linux] Run Python script through cron? Winfried 2 2,053 Oct-19-2024, 06:29 PM
Last Post: Winfried
  [SOLVED] [Linux] Write file and change owner? Winfried 6 3,192 Oct-17-2024, 01:15 AM
Last Post: Winfried
  Start print a text after open an async task via button Nietzsche 0 1,603 May-15-2023, 06:52 AM
Last Post: Nietzsche
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 2,173 Nov-16-2022, 07:58 PM
Last Post: Winfried
  [Solved] How to print a dot leader. BashBedlam 4 3,681 Jan-02-2022, 04:28 PM
Last Post: BashBedlam
Question (solved) open multiple libre office files in libre office lucky67 5 6,834 May-29-2021, 04:54 PM
Last Post: lucky67
  Use different Anaconda environments on Linux Mint and Spyder StaLLoNe_CoBRa 0 2,907 Jan-20-2021, 03:12 AM
Last Post: StaLLoNe_CoBRa
  Make color for string when print to console hadoan 6 6,099 Oct-31-2019, 01:40 PM
Last Post: hadoan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020