Python¶
The primary interface to virtualenv is the command line application. However, it can also be used programmatically
via the virtualenv.cli_run function and the Session class.
See Use virtualenv for usage examples.
virtualenv module¶
- virtualenv.cli_run(args, options=None, setup_logging=True, env=None)¶
Create a virtual environment given some command line interface arguments.
- Parameters:
args (
list[str]) – the command line argumentsoptions (
Optional[VirtualEnvOptions]) – passing in aVirtualEnvOptionsobject allows return of the parsed optionssetup_logging (
bool) –Trueif setup logging handlers,Falseto use handlers already registeredenv (
Optional[MutableMapping[str,str]]) – environment variables to use
- Return type:
- Returns:
the session object of the creation (its structure for now is experimental and might change on short notice)
- virtualenv.session_via_cli(args, options=None, setup_logging=True, env=None)¶
Create a virtualenv session (same as cli_run, but this does not perform the creation). Use this if you just want to query what the virtual environment would look like, but not actually create it.
- Parameters:
args (
list[str]) – the command line argumentsoptions (
Optional[VirtualEnvOptions]) – passing in aVirtualEnvOptionsobject allows return of the parsed optionssetup_logging (
bool) –Trueif setup logging handlers,Falseto use handlers already registeredenv (
Optional[MutableMapping[str,str]]) – environment variables to use
- Return type:
- Returns:
the session object of the creation (its structure for now is experimental and might change on short notice)
Session class¶
The Session class represents a virtualenv creation session and provides access to the created environment’s
properties.
- class virtualenv.run.session.Session(verbosity, app_data, interpreter, creator, seeder, activators)¶
Represents a virtual environment creation session.
- Parameters:
verbosity (
int) –app_data (
AppData) –interpreter (
PythonInfo) –creator (
Creator) –seeder (
Seeder) –activators (
list[Activator]) –
- property verbosity: int¶
The verbosity of the run.
- property interpreter: PythonInfo¶
Create a virtual environment based on this reference interpreter.
- property creator: Creator¶
The creator used to build the virtual environment (must be compatible with the interpreter).
- property activators: list[virtualenv.activation.activator.Activator]¶
Activators used to generate activations scripts.
VirtualEnvOptions¶
Options namespace passed to plugin constructors, populated from the CLI, environment variables, and configuration files.
- class virtualenv.config.cli.parser.VirtualEnvOptions(**kwargs)¶
- Parameters:
kwargs (
Any) –
- set_src(key, value, src)¶
Set an option value and record where it came from.
- Parameters:
key (
str) – the option namevalue (
Any) – the option valuesrc (
str) – the source of the value (e.g."cli","env var","default")
- Return type:
None
- get_source(key)¶
Return the source that provided a given option value.
- Parameters:
key (
str) – the option name- Return type:
Optional[str]- Returns:
the source string (e.g.
"cli","env var","default"), orNoneif not tracked
- property verbosity: int | None¶
The verbosity level, computed as
verbose - quiet, clamped to zero.- Returns:
the verbosity level, or
Noneif neither--verbosenor--quiethas been parsed yet