For python3, pip can be used by using command pip3. However, we can instruct OS to create a
short version of this.
nano ~/.bashrc
Once you open this file, scroll to the bottom and add the following line, and then save and close
the file.
alias pip=pip3
Now, we should be able to install Python packages using pip.
Now, we can start coding in Python. Before writing our first program, let’s quickly take a
look at the development environment.
Development Environment
Python does not need a special IDE (Integrated Development Environment) to create programs.
We can use any simple text editor such as nano, vim, and emac. Please note that since Raspberry
Pi uses Linux distribution and hence we have to program it in a Linux based text editors such
as nano and vim. Python files are stored with “.py” extension, so you can name your file like
“helloworld.py”. You may also use an IDE to code. There are a lot of IDEs available and each
one brings dierent features. So depending on your choice you can go with any one of them.
Raspbian, Raspberry Pi ocial operating system, has three preinstalled IDEs such as IDLE,
Geany, and Thonny. Let’s have a quick look on those.
Python IDEs
Idle
This is quite an old IDE that available for a long time. It has a built-in interpreter that helps in
testing the code by allowing running commands one at a time. However, it does not show line
numbers and only works with Python.
You can use this by clicking on Raspberry Pi logo in the top-left, and click Programming ->
Python 3 (IDLE). This will open up Python Interactive Interpreter.
Geany
This is another beginner-friendly IDE that supports multiple languages. This is the biggest
dierence between Geany and IDLE, however, it does not start with a Python interactive inter-
preter.
You can open Geany similar way as IDLE by clicking on Raspberry Pi logo in the top-left,
and click Programming -> Geany.
Thonny
This is the third one which comes pre-installed with Raspbian. This loads the interactive envi-
ronment for Python. Again, you can open Thonny similar way as IDEL and Geany by clicking
on Raspberry Pi logo in the top-left, and click Programming -> Thonny.
Programming in Python
Python is extremely easy to use a programming language with straightforward syntax. It does
not enforce any boilerplate code such as Java and C# “print” is the simplest directive to print a
336 Internet of Things
Internet_of_Things_CH13_pp327-348.indd 336 9/3/2019 10:17:04 AM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.152.162