Installing the Dependencies
00:00 The code editor I’m using is VS Code, but you basically can follow along with any code editor of your choice. I’m currently having the terminal open where I will start with the project. I already navigated to my project folder, and one of the first steps you usually want to do when creating a new Python project is creating a virtual environment.
00:21
That way you can make sure all the packages that you install are only installed for this project and not system-wide. To create a virtual environment, you’ll use the venv
module that Python comes with, and the command is python -m venv
.
00:37
The second word is the name of my virtual environment. You can basically name it any way you want, but I like it to be straightforward and be just venv
.
00:47
Once I hit Enter, you see on the left side that there is a new folder created named venv
. That’s the virtual environment. To actually use it, you need to activate it.
00:56
So on macOS, it’s source
venv/bin/activate
.
01:05
On Linux, it’s exactly the same command, and on Windows, you will use venvScriptsactivate
.
01:13 You can verify that the virtual environment activated if you see the virtual environment’s name in parentheses on the left of your prompt.
01:21 Now that the virtual environment is there and activated, I will install the packages that you need for this project, and that’s Flask, Pygments, and Playwright.
01:31
You can install all three packages in one command using python -m pip install Flask
Pygments playwright
.
01:42 So that’s P-L-A-Y-W-R-I-G-H-T to work with my German accent so you know what I’m typing there, and all three packages separated by a space. And once you hit Enter, then all the packages are installed in one go.
02:03 As you saw, I didn’t specify any version numbers for those packages, so I’m currently using the up-to-date versions as of the day of this recording. But since you’re watching this course sometime in the future, the versions might have changed.
02:17
So I will freeze the packages’ versions in a requirements
.txt
file and you can use this requirements.txt
file that you can find in the supporting materials to download exactly the versions I’m using in this course so you can follow along and you can be sure the code works exactly as you see it on the screen.
02:34
To freeze packages in a requirements.txt
file, you type python -m pip freeze
, and then a greater than sign, and then a filename, in this case requirements.txt
.
02:50
If you want to use the requirements file from the supporting materials, the command that you’ll use is python -m pip install
02:59
-r
, and then you add the requirements.txt
file as the argument.
03:05 And once you hit Enter, you will see that the requirements are already satisfied for me but for you, you will then install exactly the versions from this video course.
03:14 And with the packages in place, there is actually one important step that you need to do in order to work with Playwright later, and that’s to install the headless browsers.
03:24
So inside your virtual environment type python -m
playwright install
. When you press Enter, then Playwright installs the required browsers for you.
03:37
This might take a while, so I’ll ask my video editor to speed up this process. Using Playwright install
installs the latest versions of Chromium, Firefox, and WebKit.
03:46 These are basically similar to the browsers that you’re using to explore the web. The main difference here is that these browsers are headless in Playwright.
03:56 That means that they don’t have a graphical user interface, but instead, Playwright uses this to run them in the background. And you can control those browsers programmatically, and that’s what you will do in this project.
Become a Member to join the conversation.