post icon

How to run Python program on Raspberry Pi LXTerminal

If you are new to using Python on the Raspberry Pi, this article may help you.
First of all, let’s create a simple Python program directly from RPi module, using LeafPad text editor provisioned out of the box with Raspbian operating system.
Therefore, let’s open LeafPad, past the following Python program code snippet:

import datetime

dt = datetime.datetime.now()

print str(dt) 

and save the fine on Desktop with name DateTimeProgram.py

Now open Raspbian terminal LXTerminal and type the following command to reach the Desktop folder:

cd /home/pi/Desktop

Next, type the following command to run DateTimeProgram Python program and type Enter key:

python DateTimeProgram.py

The program should now be running and print the dae and time on the output console.

2 Comments

Leave a comment
  1. emiliano
    November 30th, 2015 at 10:26 #

    un altro modo è quello di aggiungere al file, nella prima linea, lo shabang
    #!/usr/bin/python

    dare i diritti di esecuzione al file con

    chmod +x DateTimeProgram.py

    ed infine eseguire direttamente il file, sempre dalla dir Desktop,

    ./DateTimeProgram.py

Leave a Reply

Are you human? Time limit is exhausted. Please reload CAPTCHA.