User Guide

149
Installing a Module
You can find many additional Python modules that you can
download and install with the Package Manager in Raspbian.
If you download a module without using the Package Manager,
you will have to install it yourself. Modules usually come with an
installation script (setup.py) that copies the module(s) to the
correct location on your system. To run it:
1. On the Application Launcher, click LXTerminal.
2. Move into the folder that contains the module that
you want to install. Use the cd command.
3. Type the following command and then press Enter:
python3 setup.py install
Using a Module
Before you can use a class or function from a module, you need
to import it into your project.
To import the entire module, put an import statement at the top
of your .py script. For example, to import the math module use
the statement:
import math
Then access items from a module using the dot syntax, as you do
when working with objects. For example, to call the floor()
function in the math module:
math.floor(10.3)
If you only want to import a specific item from a module, rather
than everything that the module contains, you can use the
from…import syntax. In the following example, only the floor()
function is imported and so the call to the ceil() function
generates an error.
from math import floor
print(floor(10.3))
print(ceil(10.7))