🛠️Virtual Environment
Also known as venv, Python Virtual Environment, virtualenv, .venv
A folder for one project. It holds the Python code that project needs.
Think of it like
It is like giving each child their own toy box. One child's mess never ends up in another's box.
Example
Emma's old project needs an old version of a package, and her new one needs the latest. Each gets its own .venv, and both work.
Why it matters
Without one, all your projects share the same packages. Then an update for one project can break another.
Definition
Example code
console
$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip install requestsCommon mistake
Key takeaways
- 1One per project. Each project gets its own folder.
- 2Turn it on first. Then installs go into that folder.
- 3Throw it away freely. Do not commit it; rebuild it any time.