We earn commission when you buy through affiliate links.

This does not influence our reviews or recommendations.Learn more.

You should probably know how to run Python scripts if you are familiar with Python.

Why should you read this article?

And another chance that you dont know how to run Python scripts as you are not familiar with them.

Its definitely for you.

Is this only for you?

No, both who are familiar and who are not with Python can get something new in this article.

Without further ado lets jump into the article.

Before going into the execution part of the tutorial, we need to have installed Python on our systems.

Open a text editor and create a Python script to use throughout this tutorial.

you might use the following script of adding two numbers.

IDE

you could trigger the Python scripts withIDEusing a single click.

Running Python scripts in IDE is a straightforward thing.

You will find a button to spin up the Python script with the same name.

Click it to execute the Python script.

Lets see the steps to initiate the Python scripts using the command line or terminal.

The above steps work with all major operating systems.

There are other ways to launch the Python scripts in different operating systems.

Lets see them one by one.

Both these operating systems support bash scripts.

Lets see the steps to run Python scripts using a bash script.

#!/usr/bin/env bashpython3 /path/to_your/python/script.py

You may also want to learn how torun bash scripts in Python.

Ubuntu

There is another cool way to initiate the Python scripts in Ubuntu.

Lets say you have a GUI system thats written in Python.

Its difficult to run it by following the above methods every time.

How can we run it in a single click?

What about running it from the dashboard?

Yeah, we can create a desktop entry for the Python script.

Lets see the steps to launch the Python script from the dashboard.

you’ve got the option to change the name fromaddto anything you like.

Give the path of your script relative from the home directory in the bash script.

And update the bash script path in the above desktop entry.

You will see the GUI program.

We can see that the terminal closes after running the Python script.

We cant see the output for even a sec.

To avoid this problem, we need to keep launch the terminal even after the execution of the script.

Add a new line to the bash script as follows.

Now, run it again.

And there is output in front of you.

Windows

There is another way to launch the Python scripts in windows.

We can useRunto execute the Python scripts.

Lets see the steps to trigger the Python scripts usingRun.

Todo so, create a file with an extensionbatand paste the following code into it.

Now, once again open theRundialog withWindows Key + Rshortcut and enter the path of your batch script.

It will initiate the Python script thats given in the batch script.

you might see the output now.

Conclusion

Choose the most appropriate way to run your Python scripts.

And enjoy writing the code inPython.