0%

Isolated Environments and Packages

Create and Activate .venv

The project has a name for its boundary. Now give it one.

In the site , make sure you are in /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 to create an environment, and call the directory .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 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 ’s Python in place.

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.