WEBVTT

00:00.140 --> 00:05.510
In this section, we will continue what we started in the previous section, and we are going to focus

00:05.510 --> 00:07.310
on Python and the terminal.

00:07.340 --> 00:12.770
As a reminder, you can download a recap PDF with all the commands at the end of the last section.

00:12.770 --> 00:16.580
And here in this lesson we will see how to install Python modules.

00:16.580 --> 00:22.610
So you've already seen a few Python modules for example time and signal that are already part of the

00:22.610 --> 00:24.710
Python three built in libraries.

00:24.710 --> 00:30.170
Then you have some additional modules, for example the Gpio zero, which is not part of the built in

00:30.170 --> 00:33.500
libraries, and that you need to install manually.

00:33.500 --> 00:39.350
So actually Gpio zero, you don't need to install it because it's already included when you install

00:39.380 --> 00:40.640
Raspberry Pi OS.

00:40.670 --> 00:40.880
Okay.

00:40.910 --> 00:42.860
So the kind of install it for you.

00:42.860 --> 00:44.720
And so here we're going to see how to.

00:44.750 --> 00:50.300
Well no actually what Python modules you have installed and how to install new ones.

00:50.300 --> 00:51.620
We're going to do that from the terminal.

00:51.620 --> 00:56.600
But know that there is also an option to do that from Thonny, although I don't really recommend it.

00:56.600 --> 01:04.130
So on Thonny you have tools and then manage packages, and here you can see a list of packages and you

01:04.130 --> 01:08.030
can for example, type the name here Gpio zero.

01:08.060 --> 01:09.590
Let's search.

01:10.040 --> 01:16.420
You find the Gpio zero here and you see well, it's already installed, but if it was not installed

01:16.420 --> 01:18.220
you could choose to install it.

01:18.220 --> 01:23.470
But here and also as best practice, I would recommend not to install modules from here and just to

01:23.470 --> 01:24.580
do it from the terminal.

01:24.610 --> 01:24.850
Okay.

01:24.880 --> 01:26.710
So I'm going to close Tony.

01:26.710 --> 01:33.010
So how to list all the Python modules that you have while you have this command Pip3 that will allow

01:33.010 --> 01:34.630
you to manage Python modules.

01:34.630 --> 01:39.670
And then you can do pip three space list, press enter.

01:39.670 --> 01:42.490
And you see you have a long list of Python modules.

01:42.490 --> 01:45.610
So those are all the ones that are installed.

01:45.610 --> 01:48.220
And for example we can find.

01:48.220 --> 01:49.930
So that's going to be here.

01:50.200 --> 01:52.750
You can find Gpio zero.

01:52.750 --> 01:58.570
So you have the name of the module and also the version number.

01:58.570 --> 01:59.770
So it might be different for you.

01:59.770 --> 02:04.900
But at least you can see all the names with all the version numbers for all the Python modules that

02:04.900 --> 02:05.440
you have.

02:05.470 --> 02:10.960
Now if I come back here and if you actually want to search for a specific module, I'm going to give

02:10.960 --> 02:12.160
you a quick tip.

02:12.160 --> 02:14.770
So you do pip three list.

02:14.980 --> 02:18.760
Then you can do pip and after pipe you put grep okay.

02:18.790 --> 02:23.060
This is going to filter depending on what you put here.

02:23.060 --> 02:24.830
So for example Gpio.

02:24.860 --> 02:33.020
This is going to filter the result of that command and only outputs the lines that match with this here

02:33.020 --> 02:33.500
on the right.

02:33.500 --> 02:35.480
So here you can see where we have a few things.

02:35.480 --> 02:38.000
But you can see we have the Gpio zero right here.

02:38.000 --> 02:40.160
So it's a bit easier to find it.

02:40.190 --> 02:40.610
Great.

02:40.610 --> 02:43.280
So with this you can know what libraries you have.

02:43.280 --> 02:47.090
You can find a specific library and see what version you have for that library.

02:47.120 --> 02:50.180
Now how to install a Python module.

02:50.180 --> 02:52.610
So note here I use library and module.

02:52.610 --> 02:54.680
This is basically the same thing.

02:54.680 --> 02:55.790
Just that in Python three.

02:55.820 --> 03:00.290
Usually we use the term module I'm going to clear and how to install a Python module.

03:00.290 --> 03:01.850
Well you have two ways.

03:01.880 --> 03:06.050
And the way that we're going to prefer here is with apt.

03:06.050 --> 03:09.620
So we're going to do sudo apt install.

03:09.680 --> 03:14.900
And then you're going to start with Python three dash and then the Python module.

03:14.900 --> 03:17.000
So if it's available you can install it.

03:17.000 --> 03:23.660
Not all Python modules would be available for installation with APT, but if it's there you can install

03:23.660 --> 03:25.460
it for example Gpio zero.

03:25.460 --> 03:27.920
And note here I'm going to press tab.

03:28.190 --> 03:32.200
And you see it's actually recognised means that it exists.

03:32.230 --> 03:33.760
So I'm going to press enter.

03:34.330 --> 03:36.310
And what you can see what's already installed.

03:36.310 --> 03:37.090
So nothing new.

03:37.090 --> 03:40.960
So that's how you can install globally a Python module.

03:40.960 --> 03:45.580
And I would recommend to use that every time you can, especially on the Raspberry Pi.

03:45.610 --> 03:48.340
Then an alternative is to use Pip3.

03:48.340 --> 03:50.650
So I'm coming back to this pip3 command.

03:50.650 --> 03:52.330
This time we've installed.

03:52.330 --> 03:54.790
And here you don't need sudo in front.

03:54.820 --> 03:57.280
So pip3 install and then you put the name.

03:57.280 --> 03:59.530
So just Gpio zero okay.

03:59.650 --> 04:03.070
Press enter and you might see this error okay.

04:03.100 --> 04:05.440
Error externally managed environment.

04:05.440 --> 04:12.370
And this is because now while pip3 is a bit more strict and they want you to create a virtual environment

04:12.370 --> 04:15.280
and then to only install the packages in that environment.

04:15.280 --> 04:21.670
Or you can see they also recommend you to install Python packages here with apt install Python three

04:21.970 --> 04:24.910
module, which is exactly what we did here.

04:24.910 --> 04:30.820
But if you still want to use pip three, then you still want to install the package in an easy way,

04:30.820 --> 04:33.520
especially if you work on the Raspberry Pi, there's going to be much easier.

04:33.520 --> 04:35.440
You can add this option here.

04:35.440 --> 04:37.720
Break system packages.

04:37.720 --> 04:44.810
So I'm going to run the same command and then dash, dash brake system packages.

04:44.810 --> 04:47.870
You can just copy and paste also from here if you want.

04:47.900 --> 04:48.080
Okay.

04:48.110 --> 04:50.270
So I press enter and now it's going to work.

04:50.270 --> 04:54.290
And what he is not going to install anything because it was already installed for me.

04:54.320 --> 04:54.590
All right.

04:54.620 --> 04:57.800
So that's how you can install a Python package.

04:57.830 --> 05:02.780
Again I will recommend that you use the apt install if possible.

05:02.780 --> 05:05.360
And then well we have a package.

05:05.360 --> 05:08.120
How to remove it I'm going to do clear.

05:08.150 --> 05:11.900
Well if you have installed it with apt you can remove it with apt.

05:11.930 --> 05:16.010
So sudo apt remove and then the name of the package.

05:16.010 --> 05:19.880
For example Python three dash gpio zero.

05:19.910 --> 05:21.230
I'm not going to do it okay.

05:21.230 --> 05:25.880
But basically it's the same thing as what we did before with normal packages.

05:25.880 --> 05:28.550
And then you can also do pip3.

05:28.550 --> 05:33.440
And this time the command is not remove but it's uninstall.

05:34.070 --> 05:35.060
So tiny difference.

05:35.060 --> 05:36.290
And then Gpio zero.

05:36.290 --> 05:40.520
And this is going to uninstall the package with pip three.

05:40.520 --> 05:43.160
And well I'm not going to run this command as well.

05:43.190 --> 05:43.640
All right.

05:43.640 --> 05:46.850
And with that you have everything you need to install new Python modules.

05:46.850 --> 05:49.640
And to finish all the projects for this course.
