Before we start coding, we need to discuss virtual environments.
Let's first answer the question why do we need to have a virtual environment?
Let's consider you started to develop an application on your laptop using Python 3.4.
This will have its respective libraries, and these libraries will in turn have their specific versions.
Now consider you want to create a new application and you require Python 3.10 due to the upgrades done
since 3.4 to 3.10, and you therefore like to use the newer features.
Without virtual environments, you can only have one version of Python installed at a time, which means
that if you come to upgrade to from 3.4 to 3.10, you run the risk of breaking some features of the
first step when you continue to develop on it.
This is especially the case if Python 3.10 is not backwards compatible with version 3.4.
To avoid this issue, we can isolate these two apps into two separate environments, and like this.
We will not have any issues to create a virtual environment or them in short.
First, make sure you have your folder path set up where you will store all the code locally.
This step we have already done in the last lecture, and I showed you that in my case, I will build
this project under this path.
Now to create the Venv.
This will differ slightly.
If you are on windows, Mac or Linux, make sure you are in a project directory, which in my case is
YouTube LTE.
There are instructions on how to create a Venv depending on your OS and the Python documentation, which
I will put in the appendix of this section on windows.
The steps are as follows.
Type in Python dash m venv and you will also specify the name of the Venv.
We can give it the same name as bank.
Once it finishes initializing, you will see a folder being created with the name which we gave it.
To actually activate the Venv.
In my case, since I'm using PowerShell, we would write the following command to write Venv scripts.
Rips.
Activates the PS1.
This part is referring to the PowerShell script that we have here.
As you can see, the Venv environment has been activated.
Now these commands differ slightly if you are using Mac or Linux.
I believe that if you are using Mac or Linux, you'd have to write python3 here instead of just Python.
And also in order to activate you would run a command similar to source Venv been activated.
Now from here you will be able to install the libraries you need using Pip.
If you want to exit your virtual environment just right, deactivate.
And obviously again if you want to reactivate you would run the same command as before.
You might also want to do this if you close VSCode and don't see them showing up in the terminal.
No worries.
If this happens, just rerun deactivate Venv command.
Before we close off this lecture, I'd like to go over two concepts which I think will be useful for
you to know.
You might have noticed on the left hand side that I now have one K plus files showing up on the source
control view.
This happened because well for starters when you create event.
Many files will be created in order to set up the virtual environment.
But we are seeing these files here because once I initialize the git repository using the git init command,
all of the files that are present locally are waiting to be committed to GitHub.
So we have to press on.
Here you would see all these files that are waiting to be uploaded to GitHub.
However, the folder is not something you would need to commit to GitHub so we can use what is called
a.
Gitignore file.
Let's create it right now.
This creates a folder until you create a file.
So go in here.
Dot get ignore.
And inside the git ignore file you can write venv.
And like this.
It will ignore any venv folders when you come to commit and push to GitHub.
As you can see, once we saved, the folder here becomes transparent.
Another concept we should discuss relates to Picache.
When we will start to code, we'll see the spike folders being automatically created by Python with
spike extension files.
What is happening here is that when you run a Python script, Python compiles your code into bytecode,
which is a more efficient, machine readable version of your code.
And ultimately these files help your programs run faster.
Same as for the folder, we can add these picache folders to the gitignore file.
Let's do that right now.
And we save.
Now that we have also covered visual environments, we just have one more topic to cover before we start
coding.
It is important that before you write any piece of code, you identify what are the aims and end goals
of the code.
So in the next lecture, we will do an analysis of what variables will be extracted from the API that
will ultimately be stored in our data warehouse.
I will see you then.