@@ -37,14 +37,14 @@ A virtual environment is (amongst other things):
3737 are by default isolated from software in other virtual environments and Python
3838 interpreters and libraries installed in the operating system.
3939
40- * Contained in a directory, conventionally either named ``venv `` or ``. venv `` in
40+ * Contained in a directory, conventionally named ``. venv `` or ``venv `` in
4141 the project directory, or under a container directory for lots of virtual
4242 environments, such as ``~/.virtualenvs ``.
4343
4444* Not checked into source control systems such as Git.
4545
4646* Considered as disposable -- it should be simple to delete and recreate it from
47- scratch. You don't place any project code in the environment
47+ scratch. You don't place any project code in the environment.
4848
4949* Not considered as movable or copyable -- you just recreate the same
5050 environment in the target location.
@@ -61,7 +61,121 @@ See :pep:`405` for more background on Python virtual environments.
6161Creating virtual environments
6262-----------------------------
6363
64- .. include :: /using/venv-create.inc
64+ :ref: `Virtual environments <venv-def >` are created by executing the ``venv ``
65+ module:
66+
67+ .. code-block :: shell
68+
69+ python -m venv /path/to/new/virtual/environment
70+
71+ This creates the target directory (including parent directories as needed)
72+ and places a :file: `pyvenv.cfg ` file in it with a ``home `` key
73+ pointing to the Python installation from which the command was run.
74+ It also creates a :file: `bin ` (or :file: `Scripts ` on Windows) subdirectory
75+ containing a copy or symlink of the Python executable
76+ (as appropriate for the platform or arguments used at environment creation time).
77+ It also creates a :file: `lib/pythonX.Y/site-packages ` subdirectory
78+ (on Windows, this is :file: `Lib\s ite-packages `).
79+ If an existing directory is specified, it will be re-used.
80+
81+ .. versionchanged :: 3.5
82+ The use of ``venv `` is now recommended for creating virtual environments.
83+
84+ .. deprecated-removed :: 3.6 3.8
85+ :program: `pyvenv ` was the recommended tool for creating virtual environments
86+ for Python 3.3 and 3.4, and replaced in 3.5 by executing ``venv `` directly.
87+
88+ .. highlight :: none
89+
90+ On Windows, invoke the ``venv `` command as follows:
91+
92+ .. code-block :: ps1con
93+
94+ PS> python -m venv C:\path\to\new\virtual\environment
95+
96+ The command, if run with ``-h ``, will show the available options::
97+
98+ usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
99+ [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps]
100+ [--without-scm-ignore-files]
101+ ENV_DIR [ENV_DIR ...]
102+
103+ Creates virtual Python environments in one or more target directories.
104+
105+ positional arguments:
106+ ENV_DIR A directory to create the environment in.
107+
108+ options:
109+ -h, --help show this help message and exit
110+ --system-site-packages
111+ Give the virtual environment access to the system
112+ site-packages dir.
113+ --symlinks Try to use symlinks rather than copies, when
114+ symlinks are not the default for the platform.
115+ --copies Try to use copies rather than symlinks, even when
116+ symlinks are the default for the platform.
117+ --clear Delete the contents of the environment directory
118+ if it already exists, before environment creation.
119+ --upgrade Upgrade the environment directory to use this
120+ version of Python, assuming Python has been
121+ upgraded in-place.
122+ --without-pip Skips installing or upgrading pip in the virtual
123+ environment (pip is bootstrapped by default)
124+ --prompt PROMPT Provides an alternative prompt prefix for this
125+ environment.
126+ --upgrade-deps Upgrade core dependencies (pip) to the latest
127+ version in PyPI
128+ --without-scm-ignore-files
129+ Skips adding SCM ignore files to the environment
130+ directory (Git is supported by default).
131+
132+ Once an environment has been created, you may wish to activate it, e.g. by
133+ sourcing an activate script in its bin directory.
134+
135+
136+ .. versionchanged :: 3.4
137+ Installs pip by default, added the ``--without-pip `` and ``--copies ``
138+ options.
139+
140+ .. versionchanged :: 3.4
141+ In earlier versions, if the target directory already existed, an error was
142+ raised, unless the ``--clear `` or ``--upgrade `` option was provided.
143+
144+ .. versionchanged :: 3.9
145+ Add ``--upgrade-deps `` option to upgrade pip + setuptools to the latest on PyPI.
146+
147+ .. versionchanged :: 3.12
148+
149+ ``setuptools `` is no longer a core venv dependency.
150+
151+ .. note ::
152+ While symlinks are supported on Windows, they are not recommended. Of
153+ particular note is that double-clicking ``python.exe `` in File Explorer
154+ will resolve the symlink eagerly and ignore the virtual environment.
155+
156+ .. note ::
157+ On Microsoft Windows, it may be required to enable the ``Activate.ps1 ``
158+ script by setting the execution policy for the user. You can do this by
159+ issuing the following PowerShell command:
160+
161+ .. code-block :: powershell
162+
163+ PS C:\> Set-ExecutionPolicy - ExecutionPolicy RemoteSigned - Scope CurrentUser
164+
165+ See `About Execution Policies
166+ <https://go.microsoft.com/fwlink/?LinkID=135170> `_
167+ for more information.
168+
169+ The created :file: `pyvenv.cfg ` file also includes the
170+ ``include-system-site-packages `` key, set to ``true `` if ``venv `` is
171+ run with the ``--system-site-packages `` option, ``false `` otherwise.
172+
173+ Unless the ``--without-pip `` option is given, :mod: `ensurepip ` will be
174+ invoked to bootstrap ``pip `` into the virtual environment.
175+
176+ Multiple paths can be given to ``venv ``, in which case an identical virtual
177+ environment will be created, according to the given options, at each provided
178+ path.
65179
66180.. _venv-explanation :
67181
@@ -117,7 +231,7 @@ should be runnable without activating it.
117231
118232In order to achieve this, scripts installed into virtual environments have
119233a "shebang" line which points to the environment's Python interpreter,
120- i.e. :samp: `#!/{ <path-to-venv> } /bin/python `.
234+ :samp: `#!/{ <path-to-venv> } /bin/python `.
121235This means that the script will run with that interpreter regardless of the
122236value of :envvar: `PATH `. On Windows, "shebang" line processing is supported if
123237you have the :ref: `launcher ` installed. Thus, double-clicking an installed
@@ -335,8 +449,8 @@ creation according to their needs, the :class:`EnvBuilder` class.
335449 .. method :: install_scripts(context, path)
336450
337451 *path * is the path to a directory that should contain subdirectories
338- " common", " posix", "nt", each containing scripts destined for the bin
339- directory in the environment. The contents of " common" and the
452+ `` common ``, `` posix ``, `` nt ``; each containing scripts destined for the
453+ `` bin `` directory in the environment. The contents of `` common `` and the
340454 directory corresponding to :data: `os.name ` are copied after some text
341455 replacement of placeholders:
342456
@@ -370,13 +484,13 @@ There is also a module-level convenience function:
370484 .. versionadded :: 3.3
371485
372486 .. versionchanged :: 3.4
373- Added the `` with_pip `` parameter
487+ Added the * with_pip * parameter
374488
375489 .. versionchanged :: 3.6
376- Added the `` prompt `` parameter
490+ Added the * prompt * parameter
377491
378492 .. versionchanged :: 3.9
379- Added the `` upgrade_deps `` parameter
493+ Added the * upgrade_deps * parameter
380494
381495An example of extending ``EnvBuilder ``
382496--------------------------------------
0 commit comments