Your DevOps study space

Real explanations. Videos with tests. Fresh exams every time. Keep the streak alive and watch the XP stack up.

Virtual environments & packages · Python Docs · StackwisePlanDevOps Virtual environments & packages · Python Docs · StackwiseCodePython Virtual environments & packages · Python Docs · StackwiseBuildDocker Virtual environments & packages · Python Docs · StackwiseTestDevOps Virtual environments & packages · Python Docs · StackwiseReleaseGit Virtual environments & packages · Python Docs · StackwiseDeployKubernetes Virtual environments & packages · Python Docs · StackwiseOperateLinux Virtual environments & packages · Python Docs · StackwiseMonitorDevOps

Pick a topic

Eight tracks, each with docs, a cheat sheet, videos and tests.

How it works

One loop, repeated until it sticks.

Jump back in

Picked up from where you left off.

Free forever

Your DevOps journey starts with one click.

Sign in with Google or GitHub to open every chapter, video, test and challenge. Your progress is saved wherever you learn.

Virtual environments & packages

Almost every real Python project uses packages from PyPI, and every project needs its own versions of them. A virtual environment is the standard way to keep those packages separate per project, and on Ubuntu 24.04 it's no longer optional: plain pip install outside one is refused.

Why virtual environments exist

Without one, pip install puts packages into the Python that came with the operating system. That causes three problems:

  • Version clashes: project A needs requests 2.28, project B needs 2.32. One Python can only have one version installed.
  • Breaking the OS: Ubuntu's own tools are written in Python and installed with apt. Upgrading a library under them with pip can break them.
  • No record: nobody knows which packages the project actually needs, so it won't run on the next machine.

A virtual environment (venv) is a folder containing its own python, its own pip and its own site-packages folder where installs go. Each project gets one, usually called .venv inside the project.

system Pythonused by the OSapt's own toolsdon't pip herepython3/usr/binproject-a/.venvrequests 2.28its own site-packagespython, pipits own copiesproject-b/.venvrequests 2.32its own site-packagespython, pipits own copies
Each project folder gets its own Python, pip and packages. Different versions stop clashing, and the system Python stays untouched.

Create, activate, deactivate

$ cd ~/projects/monitor
$ python3 -m venv .venv                # create it (once per project)
$ source .venv/bin/activate            # Linux / macOS
(.venv) $ which python
/home/demee/projects/monitor/.venv/bin/python
(.venv) $ python -m pip install requests
(.venv) $ deactivate                   # back to the system Python

On Windows the folder is called Scripts instead of bin:

C:\monitor> py -m venv .venv
C:\monitor> .venv\Scripts\activate            <- cmd.exe
PS C:\monitor> .venv\Scripts\Activate.ps1     <- PowerShell

If PowerShell says running scripts is disabled, allow it for your user once with Set-ExecutionPolicy -Scope CurrentUser RemoteSigned.

"Activating" does nothing magic: it puts .venv/bin at the front of your PATH (see the Linux chapter on environment) and adds (.venv) to the prompt. That also means you can skip activation and call the venv's Python directly, which is exactly what you do in cron jobs, systemd services and Dockerfiles:

$ /home/demee/projects/monitor/.venv/bin/python check.py

Add .venv/ to .gitignore: it's big, contains machine-specific paths and can always be recreated. For the same reason you can't move or rename a venv folder; delete it and create a new one.

pip: installing and inspecting

(.venv) $ pip install requests                 # latest version
(.venv) $ pip install "requests==2.32.3"       # exact version
(.venv) $ pip install "requests>=2.31,<3"     # any version in a range
(.venv) $ pip install --upgrade requests       # newer version of an installed package
(.venv) $ pip uninstall requests
(.venv) $ pip list                             # everything installed
(.venv) $ pip show requests                    # version, location, dependencies

Quote version specifiers: an unquoted > or < is shell redirection. python -m pip is the same as pip but guarantees you're using the pip that belongs to that exact python, which avoids a whole class of "I installed it but it's not found" problems.

requirements.txt: recording what the project needs

(.venv) $ pip freeze > requirements.txt
(.venv) $ cat requirements.txt
certifi==2026.7.22
charset-normalizer==3.5.1
idna==3.20
PyYAML==6.0.2
requests==2.32.3
urllib3==2.8.0

# on another machine, or in CI / a Dockerfile:
$ python3 -m venv .venv && source .venv/bin/activate
(.venv) $ pip install -r requirements.txt

pip freeze lists every installed package with its exact version, including dependencies you never asked for (certifi, idna and friends come with requests). Your version numbers will differ from these. Pinning exact versions (==) means the server gets exactly what you tested; without pins, a new release published tomorrow can break a deploy that worked today. You can also write the file by hand with only your direct dependencies:

# requirements.txt
requests~=2.32.0      # 2.32.x only: bug fixes yes, new minor version no
PyYAML==6.0.2
# comments and blank lines are allowed

Tools like Poetry and uv add lock files and speed on top of this, but they're built on the same ideas: one isolated environment per project and a recorded list of versions.

pipx: Python command-line tools

Some packages are really applications you want as a command everywhere (linters, formatters, httpie), not libraries for one project. pipx installs each one into its own hidden venv and puts just the command on your PATH:

$ sudo apt install pipx
$ pipx ensurepath          # adds ~/.local/bin to PATH (open a new terminal after)
$ pipx install black
$ black --version
$ pipx list                # what's installed
$ pipx upgrade black
$ pipx uninstall black

Errors you will meet (and how to fix them)

externally-managed-environment on Ubuntu 23.04+ and Debian 12+, when you pip install outside a venv:

$ pip install requests
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    ...

This is deliberate (PEP 668): the system Python belongs to apt. Fixes, best first: use a venv; for a library a system tool needs, sudo apt install python3-requests; for a command-line app, pipx install. The flag --break-system-packages exists, but its name is an honest description of what it can do.

No venv module on a fresh Ubuntu:

$ python3 -m venv .venv
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.12-venv
...
$ sudo apt install python3-venv      # installs the right python3.X-venv, then create the venv again

Similarly, pip: command not found or python: command not found outside a venv is normal on Ubuntu 24.04: the command is python3, and pip comes from sudo apt install python3-pip. Inside an activated venv both python and pip exist.

ModuleNotFoundError: No module named 'requests' almost always means the package was installed into a different Python from the one running your script: the venv isn't activated, the script runs under sudo or cron (both use the system Python), or your editor picked another interpreter. Ask Python which one it is:

$ python -c "import sys; print(sys.executable)"
$ python -m pip --version    # shows which Python this pip installs into

Also check the import name, which isn't always the package name: pip install PyYAML gives import yaml, pip install python-dotenv gives import dotenv, pip install beautifulsoup4 gives import bs4.

Questions

Pick an answer. Get it wrong and you can try again right away, no waiting. 10 questions per topic - pick a filter below, then use Recreate questions for a fresh set on that topic.

Fresh questions every time

Exam

A mixed test across the whole site, shuffled so you never know which topic comes next. When you submit, every mistake comes with the reason and a jump to the exact moment in the video that explains it.

30 questions 6 topics 20 minute limit Up to 70 XP
1–4 answer · ←→ move
History

Essay

0 / 200-250 words
Sample answer
History
0:00 / 0:00
Not started

on YouTube
Subscribe

Topic progress

Activity

Achievements

Settings

Your profile and your account.

Profile details

* Required. Saved in this browser until you sign in.

Letters, numbers, dots, dashes and underscores.
0 / 160

Account

Checking…

App

Install Stackwise on your phone or computer. It opens in its own window from your home screen, and the Docs and cheat sheets you've opened keep working without internet.

Only admins can see this

Dashboard

Sign-ups, activity, messages and reviews in one place.

Prove it

Certificates

Pass a topic's test and get a certificate with its own public page you can share or add to LinkedIn. Each test is 10 questions drawn at random and graded on the server; you need 8 right, you have 15 minutes, and you get one try per topic a day.

From first command to production

Linux for DevOps

A path through Linux the way DevOps engineers use it: ten stages, every command explained with its flags, examples, real output and mistakes, the combinations engineers chain together, and incidents worked through step by step. Practise everything in a safe lab folder.

Before the interview

Interview prep

Questions that come up in real DevOps interviews, with the kind of answer that lands. Say yours out loud first, then compare. Each one links to the chapter that goes deeper.

    Private to you

    My notes

    Everything you wrote down while watching and reading, in one place. Saved to your account, never shown to anyone.