Welcome to my Python coding tutorial! In this video, we will dive into the process of creating and activating a Python virtual environment for your Python projects on a Windows computer. If you're new to Python development, setting up a virtual environment is an essential step to ensure that your project dependencies are properly managed and isolated from your system Python.
We start by opening Visual Studio Code, where I will guide you through the process of creating a project folder called "test." Once your project folder is set up, we'll open the terminal and navigate to this folder. This is where we will execute the necessary commands to create the virtual environment.
The first command we'll run is `python -m venv name_of_the_folder`, where we will specify a folder name, typically `venv` or something similar, to contain all the virtual environment files. After executing the command, you'll see that no output is returned in the terminal, but a new folder named "venv" will appear in your project directory. By expanding this folder, you'll find several files and subfolders, with the "Scripts" folder being of particular importance.
In the "Scripts" folder, you’ll find an "activate" script, which is the program we’ll use to activate the virtual environment. I will explain step-by-step how to run the activation script and what to do if you encounter an issue with the execution policy on your Windows machine. If you receive an error preventing you from running the script, I’ll show you how to change the execution policy to allow it to work.
Once the virtual environment is activated, you’ll see the `(venv)` prefix in your terminal prompt, confirming that the environment is ready. From here, you can start installing the necessary dependencies and packages for your project, and they will be confined to this virtual environment rather than affecting your system-wide Python installation.
By the end of this video, you'll have a solid understanding of how to create, activate, and use a Python virtual environment on Windows. If you find this tutorial helpful, please like the video and subscribe for more coding tutorials. If you have any questions or feedback, feel free to leave them in the comment section below. Thanks for watching, and happy coding!
Commands Used:
The command for creating the virtual environment is: python -m venv venv.
To check the execution policy, use: Get-ExecutionPolicy.
To change the execution policy, run: Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted -Force