Isolated Environments and Packages
Create and Activate .venv
The project has a name for its boundary. Now give it one.
In the site /workspace, then run:
python -m venv .venv
There may be a quiet pause. Python is creating a directory and putting a small environment inside it. When the prompt returns, the command has finished.
python -m venv .venv reads from left to right: run this Python, ask its included venv .venv. No package has been downloaded. venv came with Python.
Step inside the environment
Creating the directory is not the same as using it. Activate it:
source .venv/bin/activate
Your prompt should gain (.venv) at the front. That marker is useful, but it is not the mechanism. Activation temporarily changes the shell’s command lookup so python now finds the copy inside .venv first.
Check the version, then leave the environment:
python --version
deactivate
After deactivate, the prompt loses (.venv) and the shell goes back to its earlier command lookup. The .venv directory is still there. Deactivation leaves the room; it does not demolish it.
Repeat it on your own machine
For local practice, you first need a base Python installation. If local setup is unavailable, complete the site rehearsal and continue; Chapter 4 has an explicit site-only completion path.
Use the setup instructions in your operating-system tab below. Then create a new folder named python-practice in your home folder using your file manager. In your local terminal, type cd followed by the folder’s full path in double quotes. Run pwd to confirm that you are inside that folder before creating .venv.
Run python3 --version. If it is missing or older than Python 3.10, download a supported Python 3 installer from python.org, open the downloaded package and follow its installer. Open a new terminal and check python3 --version again. Keep any Apple-managed Python in place; your project environment will select the Python you use here. See the official macOS setup guide if installation needs troubleshooting.
python3 -m venv .venv
source .venv/bin/activate
python --version
python3 before activation. Inside the environment, python points at the environment’s interpreter.
Run py --version. If it reports Python 3.10 or newer, keep that installation. Otherwise install the Python install manager from python.org, then open a new PowerShell window. Run py install 3.13 to install the Python version used by this course, and check py --version before continuing. If py still fails, follow the official Windows troubleshooting guide; an older Python launcher can also own that command.
py -m venv .venv
.\.venv\Scripts\Activate.ps1
python --version
If PowerShell says script execution is disabled, do not weaken the machine-wide policy. You can still use the environment directly with .\.venv\Scripts\python.exe --version; activation is a convenience, not a requirement.
Run python3 --version and check for Python 3.10 or newer. If Python is missing or too old, use your distribution’s software manager or its official Python installation instructions. Some distributions provide venv separately: if creation below reports missing venv or ensurepip, install that distribution’s venv support or ask its administrator, then retry. Keep the
python3 -m venv .venv
source .venv/bin/activate
python --version
Some distributions call the command python instead of python3. Use the name that reported a version when you set up Python.
What does activating .venv change?
The room is ready. The next lesson puts one package inside it.
If activation behaves oddly on your own machine, ask Monty: “My prompt does not show (.venv) after activating. What should I check first?” Include the exact command you ran and what you saw.