WEBVTT

00:04.760 --> 00:07.960
Before we start coding, we need to discuss virtual environments.

00:08.360 --> 00:12.520
Let's first answer the question why do we need to have a virtual environment?

00:13.080 --> 00:17.600
Let's consider you started to develop an application on your laptop using Python 3.4.

00:18.240 --> 00:23.440
This will have its respective libraries, and these libraries will in turn have their specific versions.

00:24.440 --> 00:30.760
Now consider you want to create a new application and you require Python 3.10 due to the upgrades done

00:30.960 --> 00:36.480
since 3.4 to 3.10, and you therefore like to use the newer features.

00:36.960 --> 00:42.280
Without virtual environments, you can only have one version of Python installed at a time, which means

00:42.280 --> 00:49.000
that if you come to upgrade to from 3.4 to 3.10, you run the risk of breaking some features of the

00:49.000 --> 00:51.640
first step when you continue to develop on it.

00:52.000 --> 00:57.680
This is especially the case if Python 3.10 is not backwards compatible with version 3.4.

00:57.840 --> 01:04.000
To avoid this issue, we can isolate these two apps into two separate environments, and like this.

01:04.240 --> 01:09.510
We will not have any issues to create a virtual environment or them in short.

01:09.750 --> 01:14.470
First, make sure you have your folder path set up where you will store all the code locally.

01:15.790 --> 01:20.910
This step we have already done in the last lecture, and I showed you that in my case, I will build

01:20.910 --> 01:22.750
this project under this path.

01:23.030 --> 01:24.430
Now to create the Venv.

01:24.470 --> 01:25.910
This will differ slightly.

01:26.070 --> 01:32.910
If you are on windows, Mac or Linux, make sure you are in a project directory, which in my case is

01:32.910 --> 01:34.190
YouTube LTE.

01:36.070 --> 01:40.790
There are instructions on how to create a Venv depending on your OS and the Python documentation, which

01:40.790 --> 01:44.310
I will put in the appendix of this section on windows.

01:44.350 --> 01:45.670
The steps are as follows.

01:46.510 --> 01:53.910
Type in Python dash m venv and you will also specify the name of the Venv.

01:54.150 --> 01:56.750
We can give it the same name as bank.

01:57.590 --> 02:02.830
Once it finishes initializing, you will see a folder being created with the name which we gave it.

02:05.230 --> 02:06.990
To actually activate the Venv.

02:07.030 --> 02:15.070
In my case, since I'm using PowerShell, we would write the following command to write Venv scripts.

02:15.070 --> 02:15.180
Rips.

02:17.220 --> 02:19.380
Activates the PS1.

02:19.660 --> 02:25.340
This part is referring to the PowerShell script that we have here.

02:27.340 --> 02:30.940
As you can see, the Venv environment has been activated.

02:32.180 --> 02:35.380
Now these commands differ slightly if you are using Mac or Linux.

02:35.740 --> 02:41.900
I believe that if you are using Mac or Linux, you'd have to write python3 here instead of just Python.

02:42.740 --> 02:52.500
And also in order to activate you would run a command similar to source Venv been activated.

02:56.180 --> 03:00.060
Now from here you will be able to install the libraries you need using Pip.

03:00.380 --> 03:04.420
If you want to exit your virtual environment just right, deactivate.

03:06.900 --> 03:11.420
And obviously again if you want to reactivate you would run the same command as before.

03:12.180 --> 03:16.860
You might also want to do this if you close VSCode and don't see them showing up in the terminal.

03:16.900 --> 03:17.580
No worries.

03:17.580 --> 03:20.620
If this happens, just rerun deactivate Venv command.

03:21.580 --> 03:26.610
Before we close off this lecture, I'd like to go over two concepts which I think will be useful for

03:26.610 --> 03:27.170
you to know.

03:27.170 --> 03:33.050
You might have noticed on the left hand side that I now have one K plus files showing up on the source

03:33.050 --> 03:33.890
control view.

03:33.930 --> 03:37.130
This happened because well for starters when you create event.

03:37.170 --> 03:40.650
Many files will be created in order to set up the virtual environment.

03:40.650 --> 03:46.690
But we are seeing these files here because once I initialize the git repository using the git init command,

03:46.730 --> 03:50.450
all of the files that are present locally are waiting to be committed to GitHub.

03:50.450 --> 03:51.410
So we have to press on.

03:51.410 --> 03:57.210
Here you would see all these files that are waiting to be uploaded to GitHub.

03:57.610 --> 04:03.370
However, the folder is not something you would need to commit to GitHub so we can use what is called

04:03.410 --> 04:03.690
a.

04:03.690 --> 04:04.730
Gitignore file.

04:05.090 --> 04:06.250
Let's create it right now.

04:09.290 --> 04:12.290
This creates a folder until you create a file.

04:12.290 --> 04:13.570
So go in here.

04:15.690 --> 04:17.410
Dot get ignore.

04:19.050 --> 04:23.090
And inside the git ignore file you can write venv.

04:23.890 --> 04:24.650
And like this.

04:24.690 --> 04:30.520
It will ignore any venv folders when you come to commit and push to GitHub.

04:30.560 --> 04:35.880
As you can see, once we saved, the folder here becomes transparent.

04:37.040 --> 04:39.680
Another concept we should discuss relates to Picache.

04:40.240 --> 04:46.880
When we will start to code, we'll see the spike folders being automatically created by Python with

04:47.040 --> 04:48.720
spike extension files.

04:49.200 --> 04:55.040
What is happening here is that when you run a Python script, Python compiles your code into bytecode,

04:55.080 --> 04:58.400
which is a more efficient, machine readable version of your code.

04:58.400 --> 05:01.400
And ultimately these files help your programs run faster.

05:01.480 --> 05:05.800
Same as for the folder, we can add these picache folders to the gitignore file.

05:06.160 --> 05:07.240
Let's do that right now.

05:09.920 --> 05:10.880
And we save.

05:11.120 --> 05:16.000
Now that we have also covered visual environments, we just have one more topic to cover before we start

05:16.000 --> 05:16.560
coding.

05:17.080 --> 05:22.640
It is important that before you write any piece of code, you identify what are the aims and end goals

05:22.640 --> 05:23.360
of the code.

05:23.840 --> 05:30.200
So in the next lecture, we will do an analysis of what variables will be extracted from the API that

05:30.200 --> 05:32.560
will ultimately be stored in our data warehouse.

05:33.000 --> 05:33.920
I will see you then.
