Virtual environments in Python create isolated spaces for your projects, preventing package conflicts and keeping your system Python clean. They're essential for managing dependencies reliably across different tasks.
I am compiling some pros and cons to having a virtual environment for each Python project you start. So far here is what I have:
(NOTE: Unless otherwise noted, the commands are the same on a MAC and a Windows box)
There a several reasons you should absolutely use virtual environments.
- Dependency Isolation: Different projects can use specific package versions (e.g., one needs requests 2.25, another 2.31) without clashes.
- System Protection: Avoids polluting the global Python installation, which could break OS tools or get overwritten during updates.
- Reproducibility: Pin exact dependencies via requirements.txt, making it easy to replicate setups for teams or deployment.
Global installs lead to version mismatches, privilege issues (needing sudo), and hard-to-debug errors. Virtual environments sidestep these by containing everything per project.
- Extra Complexity: Beginners face a learning curve for setup, activation, and management, adding steps to daily workflows.
- Disk Space: Each environment duplicates Python and packages, consuming storage—especially with large libraries like TensorFlow.
- Activation Hassle: Forgetting to activate leads to errors; must repeat per session or project switch.
There are several fairly simple steps in making a virtual environment. So if you have decided that this is the best course for you, they are as follows:
- This is the first step, and not very difficult. If you are used to using a Windows machine, then you have probably done this more than once.
- Start by clicking on the windows icon (usually located on the far left of the toolbar).
- Type the command
cmd.exeand pressenteror to start a terminal on a MAC- press
Command + spaceto open spotlight - type
terminalin the search - start the built-in terminal or use iterm
- press
- You have successfully started the command program when the black screen pops up on your screen. Note that this will often default to the working directory of the logged in user (c:\users<logged-in-user-name> followed by a greater than sign, e.g. c:\users\owner>) on a MAC your will either see your-macbook:~ username$, where "your-macbook" is the name of your MAC and username is your username, or on newer macs you might see username@your-macbook ~ %, again substitue your macbook name and your username for the currect prompt.
- your‑MacBook is your computer’s hostname (name).
- ~ means you’re in your home directory.
- username is your macOS username.
- $ or % is the “prompt character” showing you can type a command.
- If you want to create your virtual environment in the current directory, you need to do nothing at all.
- If you want to create your virtual environment in another directory, you need to use the CD command to navigate to that directory before going forward. For instance, if you want to create the virtual directory in c:\users\owner\documents, use the command
cd Documents, orcd c:\users\owner\documents.
python -m venv <name of venv> at the command prompt
- You are still in the
cmd.execommand processor orterminal. - You should see a screen something akin to the screenshot below:
- Type in the command as it appears above, substituting the name of the virtual environment you wish to create.
./<virtual-environment-name>/Scripts/activate
(e.g. ./tz_medium/Scripts/activate or just tz_medium /Scripts/activate)
On a MAC issue the command
source myenv/bin/activate
5. Use the requirements.txt file to duplicate my current environment in your new virtual environment.
- After the step above, activating your virtual environment, go to the next step.
- Use the command
pip install -r requirements.txt
You have now created a new virtual environment, activated it and installed the requirements for the projects noted here. To get out of the virtual environment, and restore your usual prompt, simply give the command deactivate and press enter.

