Virtual Environment (venv) Basics
Welcome to another Bite-Sized tutorial! Today, we’re diving into virtual environments — a simple but powerful tool for managing your Python projects.
What is a Virtual Environment?
Think of a virtual environment like a box, a separate space on your computer where your project lives with its own set of Python packages. This way, different projects won’t interfere with each other.
Without virtual environments, all Python packages are installed globally, which can lead to version conflicts or unexpected bugs when working on multiple projects. Virtual environments keep everything neat and tidy.
Creating and Activating a Virtual Environment in VSCode
- Open your terminal in VSCode and navigate to your project folder.
- Create a new virtual environment by typing:
python -m venv env
Here, env is the folder name for your virtual environment—you can name it anything you like.
- To activate the virtual environment:
- On Windows, run:
.\env\Scripts\activate
- On Mac/Linux, run:
source env/bin/activate
When activated, your terminal prompt will show the virtual environment’s name, meaning you’re working inside it.
Deactivating the Virtual Environment
When you’re done working, simply type:
deactivate
This exits the virtual environment and returns you to your normal system settings.
Additional Resources
- Python Virtual Environments Official Documentation
- Real Python: Python Virtual Environments: A Primer
- VSCode Python Tutorial
What’s Next?
Next, we’ll connect your project to Git and GitHub using VSCode, so you can start tracking changes and collaborating smoothly.
Thanks for watching and happy coding!