In this instructional video, I demonstrate how to set up a virtual environment for Python development in Visual Studio Code. Starting with an empty directory, I create a new folder named ‘myproject’ and initiate VS Code within it. After closing the welcome page, I showcase the Python extensions I have installed, such as Pylance for intelligent code completion, the Python extension with its debugger and linter, and another debugger using debugpy.

Next, I create a new file, ‘app.py’, which activates Python-specific features in VS Code, indicating it’s a Python project. The editor prompts me to select a Python interpreter, for which I choose the recommended one I have previously installed. Then, I proceed to create a virtual environment by selecting the ‘create virtual environment’ option and choosing the ‘.venv’ folder with the same interpreter version.

VS Code automatically upgrades pip in the new environment and notifies me of the updates in the ‘.venv’ folder. I write a simple Python print statement in ‘app.py’ to output “hello” and run it successfully in the terminal.

After attempting to import numpy, which is not yet installed in our environment as indicated by a warning underline, I open a new terminal. VS Code informs me through ‘shell integration activated’ that the ‘.venv’ virtual environment is operational. I install numpy using ‘pip install numpy’, confirm its installation by checking the ‘.venv/lib’ directory, and notice the warning underline has disappeared in ‘app.py’.

Finally, I test a numpy function, ‘numpy.abs’, to ensure everything is working correctly. The tutorial concludes with a functional virtual environment set up for Python development in VS Code, emphasizing the importance of secure coding practices from the beginning.