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:
options (
VirtualEnvOptions|None) – passing in aVirtualEnvOptionsobject allows return of the parsed optionssetup_logging (
bool) –Trueif setup logging handlers,Falseto use handlers already registeredenv (
MutableMapping[str,str] |None) – 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, the same as cli_run but without performing the creation.
Use this if you just want to query what the virtual environment would look like, but not actually create it.
- Parameters:
options (
VirtualEnvOptions|None) – passing in aVirtualEnvOptionsobject allows return of the parsed optionssetup_logging (
bool) –Trueif setup logging handlers,Falseto use handlers already registeredenv (
MutableMapping[str,str] |None) – 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) – the verbosity level the creation runs withapp_data (
AppData) – the application data folderinterpreter (
PythonInfo) – the host interpreter the environment is based oncreator (
Creator) – the creator that builds the environmentseeder (
Seeder) – the seeder that installs the seed packagesactivators (
list[Activator]) – the activators that generate the activation scripts
- run()¶
Create the environment, seed it, activate it and write its configuration file.
- Return type:
- property interpreter: PythonInfo¶
Create a virtual environment based on this reference interpreter.
VirtualEnvOptions¶
Options namespace passed to plugin constructors, populated from the CLI, environment variables, and configuration files.
- class virtualenv.config.cli.parser.VirtualEnvOptions(**kwargs)¶
Namespace of the parsed options, with the source each value came from.
- Parameters:
kwargs (
Any) – the option values
- property verbosity: int | None¶
The verbosity level, computed as
verbose - quiet, clamped to zero.The value is
Noneuntil either--verboseor--quiethas been parsed.
- set_src(key, value, src)¶
Set an option value and record where it came from.