Python: venv start: verschil tussen versies
Uiterlijk
Nieuwe pagina aangemaakt met '=== 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). === Deactivating, uninstalling, removing === Leave the venv deactivate Uninstall a package (inside the venv) source .venv/bin/activate py…' |
Geen bewerkingssamenvatting |
||
| Regel 15: | Regel 15: | ||
Prepends .venv/bin to PATH, so python, pip, and any console scripts installed in the venv are found first. | 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). | 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 === | === Deactivating, uninstalling, removing === | ||
Huidige versie van 24 feb 2026 19:34
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/