Python Programming for Raspberry Pi, Sams Teach Yourself in 24 Hours

(singke) #1
Several changes were made to Python v3 in order to improve its longevity as a programming
language. Therefore, the time you spend learning it now will provide you benefits long into the
future.

Many systems support both Python v2 and Python v3, including Raspbian. Python v2 is provided for
backward compatibility purposes. In other words, you can run Python v2 programs on Raspbian.
However, to move you in the right direction, this book focuses on Python v3.


Checking Your Python Environment


The Raspbian Linux distribution comes with Python v3 and the necessary tools loaded by default. The
following Python items are preloaded:


A Python interpreter
An interactive Python shell
A Python development environment
Text editors

Even though all you need should be preloaded, it makes sense to double-check all the tools. These
checks take only a few minutes of your time.


Checking the Python Interpreter and Interactive Shell


To check the Python interpreter and interactive shell versions on your system, open the LXTerminal in
the LXDE GUI. Type python3 -V and press Enter, as shown in Listing 3.1.


LISTING 3.1 Checking the Python Version


Click here to view code image


pi@raspberrypi ~ $ python3 -V
Python 3.2.3
pi@raspberrypi ~ $

If you get the message command not found, then for some reason, the Python v3 interpreter is
not installed. Go to the “Installing Python and Tools” section in this hour to remedy this situation.


Checking the Python Development Environment


To see if a Python development environment has been installed, open the LXDE graphical interface
and look for the IDLE 3 icon on the desktop, as shown in Figure 3.1.

Free download pdf