In day one of Data Engineering cohort 3, one of the many things we learnt is setting up and using virtual environments, in the context of Visual Studio Code and Python on Windows.
What is a Virtual Environment
A virtual environment allows you to create a separate space for each project, and allows you to specify packages and version numbers to avoid any conflicts!
Why should I care?
Some libraries and packages might not be compatible with each other or even with certain Python versions - this can be solved using virtual environments.
How do I do it?
You can create and run a virtual environment inside the terminal in Visual Studio Code!
- In the terminal, create the virtual environment folder area (here, we name it ".venv") and structure with the following command.
- Activate the virtual environment by running the activate script within our created folder. This makes it so that you are using the Python installation from the virtual environment. You know it is working by the green text appearing in the terminal prompt as in the screenshot below.

- To ensure Virtual Studio Code uses the virtual environment's Python, select the Python from the virtual environment e.g. using ctrl + shift + p > Python: Select Interpreter.
- Now you can install your Python packages using pip install as usual within your virtual environment without affecting your global Python installation. Or, you can install packages from a given requirements.txt via the command:
This reads through the requirements text file and pip installs each package.
Now you can create Python files using the installed packages from step 4.
Remember to add your virtual environment to your .gitignore to not clog up your repository!