Before we will install our Django, we need to do something else and that will be installing virtual
environment.
And I will explain you why we need it and how to create one.
So what is virtual environment?
Virtual environment is a kind of folder.
It's an environment that we install in our folder and that's encapsulated view for our application.
That means if we want to install something and we are inside that virtual environment, that something,
the piece of software package will be installed in that virtual environment.
Otherwise when we install things with a python, it will be installed globally on our machine.
So how actually we can install something in Python?
Python three comes with a pip.
Pip and that's a package installer for Python.
And then basically what we can do is pip install and then name of the package if I will do Django right
now, this package installer will install Django globally on my computer.
That means this junk will be installed for the whole computer.
So generally this would be a bad idea because we might have more than one project in our computer and
each project will have a different Django version.
If not Django, you might have different packages installed for different projects.
So one project might might need some package, the other projects might not need it.
So in order to have something specific for the current project, we need to create a virtual environment
and that virtual environment will hold the project, encapsulate it, and it will be containing all
of the packages and libraries will install inside.
So how we can create one.
Let's go on a desktop here and inside the desktop.
What I can do is I can create virtual environment.
Actually with Python 3.5, we can do it with Python command.
So we go Python.
In my case it's Python three because I have more than one and then I will do minus m dash m, which
is make venv.
And then we can name our virtual environment.
I will name it the same way.
VNV So one is make virtual environment and then you name it.
I always name it virtual environment.
So it's easy to remember and it's quite short to type in.
So we do python3 m venv vcf.
I click enter.
If I do.
Now, as you can see, my folder has been created here and I've created a virtual environment in that
folder which is on desktop.
And now how can I actually activate it?
Because at the moment virtual environment has been created for me.
So I have virtual environment, but I haven't used it yet.
In order to use this virtual environment and the process is a little bit different on Mac and Linux
and Windows, so on.
Mac and Linux will be the processes I will show you in a second and we'll switch to Windows and I will
show you how to do it on Windows.
So basically we have virtual environments now.
So to activate, I need to type source and then I need to go to the folder Venv bin Activate.
And you can see here I start to type in and I type.
I click on my keyboard tab and that autocompletes the the path for me.
So the source.
And then I need to do activate if I will click.
Now you can see at the beginning of the line here we have the env, that's the name of my virtual environment.
Once I have it here, if I install something here like Pip, install Django.
You can see the Django is installed, but this will be installed inside the virtual environment.
Now, if I would if I will do that without that virtual environment activated, which I've done thorfinn
begin activate, then the Django would be installed globally and then I can't really use it in the same
way as I have it here.
So basically to create a new project with Django, we need to create a virtual environment.
Without it with Python3 m VMV, then we activate it and then we can install these things.
Okay, let's switch to Windows and I will show you how to do it on Windows Machine.
Okay, now we are inside Windows Machine.
Let's go to the desktop.
We're inside the desktop and let's use our let's create our virtual environment.
So Python, M, VNV, VNV, the same command as we used before.
Now I don't have to type in a three at the end here because I have only Python three.
I remove my version two from this machine because I won't use it anymore.
So I have only Python three so I can type python without any suffix.
You can see here on the desktop, I've created a new virtual environment and the folder here is for
me to use it.
It might take a while to finish that command.
Okay, Now, when this is done, we can activate that virtual environment and the command for this,
it's a little bit different.
So what we will need to do is we'll need to navigate inside that folder.
I can show you that inside here we have scripts and we have activate here.
So basically that's what we need to do.
So we do an environment.
Environment.
Scripts.
Activate.
And you can see here VNV at the beginning of the line means that our environment has been activated.
Once this is done, I can do a Pip install.
Django the same way I've done it before.
So basically Django will be installed in our virtual environment inside our folder.
So this folder inside our desktops, it's also not a good practice.
What we'll need to do in our real project is to create actually a folder containing our project files.
And also we'll need to have virtual environment folder inside this.
So usually you create a folder, you create virtual environment inside that folder and then you activate
it and you install everything from from there.
So virtual environment is a part of your setup project setup, but you don't need to include it, if
you will.
For example, put it on git because that can be easily recreated.
Virtual environment contains only the libraries and the packages that are needed for your current project.
So if you need to recreate it, you can also install it back again.
So if I want to share my project with you, I would exclude virtual environment folder and then I can
give you only the project files and you can do Pip install all the libraries needed for this project
and you will be ready to to go.
Okay.
Once we know the how to install virtual environment in the next section, I will show you how to create
our Django application.