python -m venv
Packages and runtimes
Usage
python -m venv [--upgrade-deps] <directory>Creates an isolated interpreter and site-packages inside one folder; creating it does nothing until you activate it or call .venv/bin/python directly, and the paths are baked in, so renaming the folder later breaks it.
Common flags
| Flag | Meaning |
|---|---|
| --upgrade-deps | start with an up-to-date pip |
| --system-site-packages | let it see the globally installed packages |
| --clear | empty the directory first |
| --prompt <name> | what the shell prompt should say |
| --without-pip | no pip inside |
Examples
python -m venv .venvcreates an isolated interpreter and site-packages in .venv
source .venv/bin/activatestarts using it; on Windows it is .venv\Scripts\activate
python -m venv --upgrade-deps .venvcreates it with the newest pip inside
The question is always what goes where: inside this project, or on the whole machine.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does python -m venv do?
Creates an isolated interpreter and site-packages inside one folder; creating it does nothing until you activate it or call .venv/bin/python directly, and the paths are baked in, so renaming the folder later breaks it.
Q. How do I type it?
python -m venv [--upgrade-deps] <directory> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
5 are listed here; the full set is in man python. This command sits under Packages and runtimes.
Related commands
man page: man python--m-venv