The objective of this post is to explain how to use Python in the Linkit Smart Duo Operating System.
Introduction
As explained in a previous post, we can use the Python programming language to develop applications for the Linkit Smart Duo board.
This tutorial will focus on explaining the basics of using Python in the Linkit Smart Duo which, as we will see, is pretty much the same as we would do in any Linux environment.
Since Python comes pre-installed in the board’s operating system (OpenWrt), we can start using it straight ahead.
First of all, we will need to connect to the Linkit Smart Duo through SSH. You can check a detailed guide on how to connect to the Linkit Smart Duo using a software called Putty here.
Using Python
Once establishing the connection to the Linkit Smart Duo, we can start exploring Python.
We will start by determining which version of Python comes pre-installed in the board. To do so, in the command line, we just need to type python -V and press enter. Figure 1 shows the expected result.
My board’s installation came with version 2.7.9, as seen in figure 1.
Figure 1 – Checking Python version of the Linkit Smart Duo board.
You can check more details on the available commands for Python here.
Although in Python we typically program by developing scripts in a file and running the whole script, this language also allows for the execution of separate commands in a command line style. To keep things simple, this is the approach we will follow in this introductory tutorial.
So, to launch Python’s command line, just type Python and press enter. You should get a result similar to the one shown in figure 2.
Figure 2 – Running Python’s command line.
Now, we can send some commands. So, to print the famous “Hello World”, we just need to type the following and press enter:
print “Hello World”
A “Hello World” message should be printed in the command line, as shown in figure 3.
Figure 3 – Python “Hello World” on the Linkit Smart Duo.
To finish our first test with Python’s command line on the Linkit Smart Duo, we will just issue a final command to print all the available Python Modules. To do so, we just type the following and press enter:
help(‘modules’)
We will first get a “Please wait” message, as shown in figure 4.
Figure 4 – Python’s module information fetching.
After a while, we will get the list of available modules, as shown in figure 5.
Figure 5 – List of default Python modules.
To exit Python’s command line and go back to the Operating System command line, just type the following and press enter:
exit()
Installing additional modules
Although the default Python installation already comes with a big list of modules, we may need to install some additional ones. So, the board also comes pre-installed with a Python package installer called pip.
Installing Python packages with pip is as easy as typing the following command:
pip install packageName
Naturally, to install new packages with pip we need to have our Linkit Smart Duo connected to the Internet.
We can check pip version with the command pip -V. The expected output is shown in figure 6.
Figure 6 – Printing pip version.
We can also check the modules installed with pip with the command pip freeze. The expected output is shown in figure 7.
Figure 7 – Printing pip modules.
Note that the previous pip commands should be sent from the Operating System command line and not from Python’s command line.
Pingback: Linkit Smart Duo: Blinking a LED with Python | techtutorialsx
Pingback: Linkit Smart Duo: Blinking a LED with Python | techtutorialsx
Pingback: LinkIt Smart Duo: Connecton to WiFi Network | techtutorialsx
Pingback: LinkIt Smart Duo: Connecton to WiFi Network | techtutorialsx
Pingback: LinkIt Smart Duo: Transferring files with SCP | techtutorialsx
Pingback: LinkIt Smart Duo: Transferring files with SCP | techtutorialsx
Pingback: LinkIt Smart Duo: Running a Flask server | techtutorialsx
Pingback: LinkIt Smart Duo: Running a Flask server | techtutorialsx