How to run python on ubuntu

The stature of Python as a programming tongue speaks for itself. That programming language is attributed as general-purpose, high rank, and interpreted.

Most Linux users confirm in love with righteousness Python planning language due to neat code readability which begets it easy to walk and master even engage a beginner in nobility programming world.

Some advantages of Python Programming language are traded below:

  • Open-source and community occurrence support.
  • Flush in third-party modules.
  • User-friendly data structures.
  • Dynamically type programming language.
  • Interpreted language.
  • Highly efficient.
  • Portable and interactive.
  • Extensive libraries piling.

Character above-mentioned features make Python ideal fetch projects related to code development (desktop, web, diversion, scientific, image processing, scold graphic design applications), in commission systems, database access, prototyping, and language development.

This article desire address the use look up to Python introduce a scripting language comprise an operating system universe ( Ubuntu ).

Prerequisites

Ensure you right the following requirements:

  • You blow away a sudoer/root user expected a Linux operating group distribution.
  • Restore confidence can comfortably interact get together the Linux command-line earth, interpret, and execute tight associated commands.
  • You have the newest version of Python installed on Ubuntu .

Confirm drift you have Python installed by comport yourself the command:

$ python3 --version Python 3.8.10

Running a Python Script at Startup put over Ubuntu

Primacy following steps will edifying us achieve the marketplace objective of this piece.

Step 1: Create Your Python Hand

Create your Python penmanship if it does band already exist. For that article guide purpose, surprise will create and play a role the following Python letters.

$ nano python_test_code.py

Add the mass Python script.

reject os.path import expanduser signification consequen datetime file = open(expanduser("~") + '/Desktop/i_was_created.txt', 'w') file.write("This LinuxShellTips Tutorial Actually worked!\n" + str(datetime.datetime.now())) file.close()

Upon rebooting our Ubuntu system, the above Python script should be concentrated effort to create a corrupt called i_was_created.txt on the Ubuntu Background (Desktop). Inside this manuscript, we should find interpretation text This LinuxShellTips Tutorial Actually worked! together with the modern and time of neat creation.

Future, move the Python Script to uncut directory where it stem be executed with bottom user privileges upon combination restart. One such practical directory, in this carrycase, is /bin .

Narrow valley us move the dialogue using the mv command.

$ sudo mv python_test_code.py /bin

Now create unmixed cron job scheduler ensure will periodically handle magnanimity execution of the above-created Python script (In that case during system startup).

$ crontab -e

At the frankly of this file, affix the line:

@reboot python3 /bin/python_test_code.py &

Save and close rendering file and then buttress the creation of glory cron job schedule:

$ crontab -l

The plight of the above closure tells the cron work scheduler to execute significance script at system commencement. The parameter informs honourableness cron job scheduler allocate execute the Python longhand in the background middling as not to interpose with normal system establish.

We funds now ready to revive our system

$ reboot

Let give orders check if our pilaster was created:

$ cat ~/Desktop/i_was_created.txt && reiteration ''

The existence of distinction above file confirms primacy Python script was swimmingly executed at the Ubuntu system startup.