So far when we have been using Python, we have been using Jupyter Notebook.
Today we are going to
set up a Python editor, in VS Code
initiate a Virtual ENVironment
learn to Install Modules onto our VENV
Use extensions of VS Code to automatically activate our VENV
Use the badge on our Anaconda Navigator
Open the zip file and drag your VS Code application into the applications folder on your computer.
Play with your colour themes if you want. I prefer Dark+ although if you prefer light background, it is totally up to you.
There are a few things that we need to do in order to set up the editor correctly, but firstly, let's build a folder that we will be creating a project in.
Create a new folder in your computing documents folder called Image Practice. This is our project folder, and everything that we need for the python to run will be put into here.
Open that folder.
Now we need to tell the program which python to run by creating our Virtual ENVironment
At the top of the screen, there is a Terminal menu, start a new terminal session and a new page opens at the bottom of the program.
Into terminal type:
python3 -m venv venv
What this does is creates a blank copy of Python3 for any file that is written in this folder to follow.
Speaking of, let's create a python file for it to read.
Click on the Image Practice folder and click the new file icon.
call it hello.py
With the addition of a python file, your VS Code may bring up a info box asking you to install a Python Extension. Follow that link or click the array of squares on the left hand menu.
The extension that you want is called Python. This is Microsoft's Python driver for VS Code. It let's VS Code understand and run Python code.
Now we need to select which python we want to use. Down in the extreme bottom left corner, in blue on my screen is which python version I am running. Click that and look for the "venv": venv selection that we just built. This is the python that we want this project to run on.
VS Code has an extension that will automatically do this for us and we should install that extension. Click on the array of squares again, search for Auto Venv extension and select the "Python Auto Venv" extension.
Let's test the install by writing
print("Hello World!!!")
into hello.py and click the green arrow in the top right to run the code.
To install modules into our python build we use PythonInstallingPackage of PIP for short.
We want to work with images, and Pillow is a great module for that.
In terminal, make sure the (venv) begins the line, which should have happened when we ran hello.py
In terminal type
source venv/bin/activate
Once venv has been activated, install Pillow by typing:
pip install PILLOW
Once it has been installed successfully, we are good to go for our activities for the next week.