WEBVTT

00:02.460 --> 00:08.970
Before we will install our Django, we need to do something else and that will be installing virtual

00:08.970 --> 00:09.600
environment.

00:09.600 --> 00:13.260
And I will explain you why we need it and how to create one.

00:13.260 --> 00:15.690
So what is virtual environment?

00:15.720 --> 00:18.870
Virtual environment is a kind of folder.

00:18.870 --> 00:27.420
It's an environment that we install in our folder and that's encapsulated view for our application.

00:27.450 --> 00:34.790
That means if we want to install something and we are inside that virtual environment, that something,

00:34.800 --> 00:39.720
the piece of software package will be installed in that virtual environment.

00:39.750 --> 00:45.600
Otherwise when we install things with a python, it will be installed globally on our machine.

00:45.600 --> 00:48.850
So how actually we can install something in Python?

00:48.870 --> 00:51.420
Python three comes with a pip.

00:51.930 --> 00:55.800
Pip and that's a package installer for Python.

00:56.430 --> 01:04.750
And then basically what we can do is pip install and then name of the package if I will do Django right

01:04.750 --> 01:10.360
now, this package installer will install Django globally on my computer.

01:10.360 --> 01:14.350
That means this junk will be installed for the whole computer.

01:14.350 --> 01:21.550
So generally this would be a bad idea because we might have more than one project in our computer and

01:21.550 --> 01:24.460
each project will have a different Django version.

01:24.460 --> 01:29.230
If not Django, you might have different packages installed for different projects.

01:29.230 --> 01:33.880
So one project might might need some package, the other projects might not need it.

01:33.880 --> 01:42.700
So in order to have something specific for the current project, we need to create a virtual environment

01:42.700 --> 01:49.990
and that virtual environment will hold the project, encapsulate it, and it will be containing all

01:49.990 --> 01:54.000
of the packages and libraries will install inside.

01:54.010 --> 01:55.870
So how we can create one.

01:56.140 --> 02:01.180
Let's go on a desktop here and inside the desktop.

02:01.180 --> 02:04.870
What I can do is I can create virtual environment.

02:05.080 --> 02:09.040
Actually with Python 3.5, we can do it with Python command.

02:09.040 --> 02:10.450
So we go Python.

02:11.050 --> 02:18.280
In my case it's Python three because I have more than one and then I will do minus m dash m, which

02:18.280 --> 02:20.440
is make venv.

02:22.050 --> 02:25.260
And then we can name our virtual environment.

02:25.290 --> 02:26.910
I will name it the same way.

02:26.960 --> 02:32.170
VNV So one is make virtual environment and then you name it.

02:32.190 --> 02:34.050
I always name it virtual environment.

02:34.050 --> 02:37.580
So it's easy to remember and it's quite short to type in.

02:37.590 --> 02:42.190
So we do python3 m venv vcf.

02:42.330 --> 02:43.380
I click enter.

02:47.310 --> 02:48.000
If I do.

02:48.000 --> 02:55.380
Now, as you can see, my folder has been created here and I've created a virtual environment in that

02:55.380 --> 02:57.780
folder which is on desktop.

02:57.990 --> 03:00.840
And now how can I actually activate it?

03:00.840 --> 03:05.430
Because at the moment virtual environment has been created for me.

03:05.820 --> 03:10.110
So I have virtual environment, but I haven't used it yet.

03:10.140 --> 03:16.260
In order to use this virtual environment and the process is a little bit different on Mac and Linux

03:16.260 --> 03:17.790
and Windows, so on.

03:17.790 --> 03:22.920
Mac and Linux will be the processes I will show you in a second and we'll switch to Windows and I will

03:22.920 --> 03:24.540
show you how to do it on Windows.

03:24.570 --> 03:27.360
So basically we have virtual environments now.

03:27.390 --> 03:36.210
So to activate, I need to type source and then I need to go to the folder Venv bin Activate.

03:36.210 --> 03:39.270
And you can see here I start to type in and I type.

03:39.360 --> 03:44.670
I click on my keyboard tab and that autocompletes the the path for me.

03:44.670 --> 03:46.090
So the source.

03:46.090 --> 03:49.180
And then I need to do activate if I will click.

03:49.180 --> 03:56.200
Now you can see at the beginning of the line here we have the env, that's the name of my virtual environment.

03:56.230 --> 04:05.020
Once I have it here, if I install something here like Pip, install Django.

04:07.360 --> 04:14.020
You can see the Django is installed, but this will be installed inside the virtual environment.

04:14.050 --> 04:22.090
Now, if I would if I will do that without that virtual environment activated, which I've done thorfinn

04:22.090 --> 04:29.110
begin activate, then the Django would be installed globally and then I can't really use it in the same

04:29.110 --> 04:30.760
way as I have it here.

04:30.760 --> 04:35.230
So basically to create a new project with Django, we need to create a virtual environment.

04:35.260 --> 04:41.920
Without it with Python3 m VMV, then we activate it and then we can install these things.

04:41.950 --> 04:46.330
Okay, let's switch to Windows and I will show you how to do it on Windows Machine.

04:46.960 --> 04:49.330
Okay, now we are inside Windows Machine.

04:49.330 --> 04:50.800
Let's go to the desktop.

04:51.560 --> 04:57.130
We're inside the desktop and let's use our let's create our virtual environment.

04:57.130 --> 05:04.870
So Python, M, VNV, VNV, the same command as we used before.

05:04.870 --> 05:10.480
Now I don't have to type in a three at the end here because I have only Python three.

05:10.490 --> 05:15.140
I remove my version two from this machine because I won't use it anymore.

05:15.140 --> 05:20.270
So I have only Python three so I can type python without any suffix.

05:21.480 --> 05:27.750
You can see here on the desktop, I've created a new virtual environment and the folder here is for

05:27.750 --> 05:28.920
me to use it.

05:32.260 --> 05:34.750
It might take a while to finish that command.

05:44.060 --> 05:49.880
Okay, Now, when this is done, we can activate that virtual environment and the command for this,

05:49.880 --> 05:51.590
it's a little bit different.

05:51.590 --> 05:56.870
So what we will need to do is we'll need to navigate inside that folder.

05:56.870 --> 06:03.770
I can show you that inside here we have scripts and we have activate here.

06:03.770 --> 06:06.230
So basically that's what we need to do.

06:10.440 --> 06:14.280
So we do an environment.

06:17.300 --> 06:18.440
Environment.

06:22.880 --> 06:23.720
Scripts.

06:25.870 --> 06:26.950
Activate.

06:28.550 --> 06:34.900
And you can see here VNV at the beginning of the line means that our environment has been activated.

06:34.910 --> 06:38.480
Once this is done, I can do a Pip install.

06:40.390 --> 06:43.840
Django the same way I've done it before.

06:43.840 --> 06:49.960
So basically Django will be installed in our virtual environment inside our folder.

06:49.960 --> 06:55.530
So this folder inside our desktops, it's also not a good practice.

06:55.540 --> 07:03.040
What we'll need to do in our real project is to create actually a folder containing our project files.

07:03.040 --> 07:07.480
And also we'll need to have virtual environment folder inside this.

07:07.480 --> 07:14.320
So usually you create a folder, you create virtual environment inside that folder and then you activate

07:14.320 --> 07:17.230
it and you install everything from from there.

07:17.230 --> 07:24.700
So virtual environment is a part of your setup project setup, but you don't need to include it, if

07:24.700 --> 07:25.300
you will.

07:25.300 --> 07:29.590
For example, put it on git because that can be easily recreated.

07:29.590 --> 07:36.880
Virtual environment contains only the libraries and the packages that are needed for your current project.

07:36.910 --> 07:41.420
So if you need to recreate it, you can also install it back again.

07:41.420 --> 07:47.660
So if I want to share my project with you, I would exclude virtual environment folder and then I can

07:47.930 --> 07:53.930
give you only the project files and you can do Pip install all the libraries needed for this project

07:53.930 --> 07:56.270
and you will be ready to to go.

07:56.780 --> 07:57.350
Okay.

07:57.350 --> 08:04.070
Once we know the how to install virtual environment in the next section, I will show you how to create

08:04.070 --> 08:05.810
our Django application.
