Home·Terminal commands

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

FlagMeaning
--upgrade-depsstart with an up-to-date pip
--system-site-packageslet it see the globally installed packages
--clearempty the directory first
--prompt <name>what the shell prompt should say
--without-pipno pip inside

Examples

python -m venv .venv

creates an isolated interpreter and site-packages in .venv

source .venv/bin/activate

starts using it; on Windows it is .venv\Scripts\activate

python -m venv --upgrade-deps .venv

creates 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