Naar inhoud springen

Python: venv start

Uit VanderSchaft
Versie door Dschaft (overleg | bijdragen) op 24 feb 2026 om 19:34
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)

Create & activate

In your project root

python3 -m venv .venv

Activate in zsh/bash

source .venv/bin/activate

Verify

python -V

Prepends .venv/bin to PATH, so python, pip, and any console scripts installed in the venv are found first. Sets a few Python-related vars (e.g., VIRTUAL_ENV, PYTHONHOME unset).

When running script change the shebang to the venv path as well:

#!/Users/username/.python

Deactivating, uninstalling, removing

Leave the venv

deactivate

Uninstall a package (inside the venv)

source .venv/bin/activate
python -m pip uninstall <pkg>

Remove ALL packages but keep the venv structure

python -m pip freeze | xargs -r python -m pip uninstall -y

Nuke the venv directory

deactivate 2>/dev/null || true
rm -rf .venv/