Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 15552c3

Browse files
committed
Issue #27285: Document the deprecation of the pyvenv script.
As part of the update, the documentation was updated to normalize around the term "virtual environment" instead of relying too heavily on "venv" for the same meaning and leading to inconsistent usage of either. Thanks to Steve Piercy for the patch.
1 parent 53e22bf commit 15552c3

9 files changed

Lines changed: 227 additions & 186 deletions

File tree

Doc/glossary.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ Glossary
970970
without interfering with the behaviour of other Python applications
971971
running on the same system.
972972

973-
See also :ref:`scripts-pyvenv`.
973+
See also :mod:`venv`.
974974

975975
virtual machine
976976
A computer defined entirely in software. Python's virtual machine

Doc/installing/index.rst

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
.. _installing-index:
44

5-
*****************************
6-
Installing Python Modules
7-
*****************************
5+
*************************
6+
Installing Python Modules
7+
*************************
88

99
1010

@@ -34,24 +34,24 @@ Key terms
3434

3535
* ``pip`` is the preferred installer program. Starting with Python 3.4, it
3636
is included by default with the Python binary installers.
37-
* a virtual environment is a semi-isolated Python environment that allows
37+
* A *virtual environment* is a semi-isolated Python environment that allows
3838
packages to be installed for use by a particular application, rather than
39-
being installed system wide
40-
* ``pyvenv`` is the standard tool for creating virtual environments, and has
39+
being installed system wide.
40+
* ``venv`` is the standard tool for creating virtual environments, and has
4141
been part of Python since Python 3.3. Starting with Python 3.4, it
42-
defaults to installing ``pip`` into all created virtual environments
42+
defaults to installing ``pip`` into all created virtual environments.
4343
* ``virtualenv`` is a third party alternative (and predecessor) to
44-
``pyvenv``. It allows virtual environments to be used on versions of
45-
Python prior to 3.4, which either don't provide ``pyvenv`` at all, or
44+
``venv``. It allows virtual environments to be used on versions of
45+
Python prior to 3.4, which either don't provide ``venv`` at all, or
4646
aren't able to automatically install ``pip`` into created environments.
47-
* the `Python Packaging Index <https://pypi.python.org/pypi>`__ is a public
47+
* The `Python Packaging Index <https://pypi.python.org/pypi>`__ is a public
4848
repository of open source licensed packages made available for use by
49-
other Python users
49+
other Python users.
5050
* the `Python Packaging Authority
5151
<https://www.pypa.io/en/latest/>`__ are the group of
5252
developers and documentation authors responsible for the maintenance and
5353
evolution of the standard packaging tools and the associated metadata and
54-
file format standards. They maintain a variety of tools, documentation
54+
file format standards. They maintain a variety of tools, documentation,
5555
and issue trackers on both `GitHub <https://github.com/pypa>`__ and
5656
`BitBucket <https://bitbucket.org/pypa/>`__.
5757
* ``distutils`` is the original build and distribution system first added to
@@ -62,6 +62,19 @@ Key terms
6262
of the mailing list used to coordinate Python packaging standards
6363
development).
6464

65+
.. deprecated:: 3.6
66+
``pyvenv`` was the recommended tool for creating virtual environments for
67+
Python 3.3 and 3.4, and is `deprecated in Python 3.6
68+
<https://docs.python.org/dev/whatsnew/3.6.html#deprecated-features>`_.
69+
70+
.. versionchanged:: 3.5
71+
The use of ``venv`` is now recommended for creating virtual environments.
72+
73+
.. seealso::
74+
75+
`Python Packaging User Guide: Creating and using virtual environments
76+
<https://packaging.python.org/installing/#creating-virtual-environments>`__
77+
6578

6679
Basic usage
6780
===========
@@ -100,13 +113,14 @@ explicitly::
100113
More information and resources regarding ``pip`` and its capabilities can be
101114
found in the `Python Packaging User Guide <https://packaging.python.org>`__.
102115

103-
``pyvenv`` has its own documentation at :ref:`scripts-pyvenv`. Installing
104-
into an active virtual environment uses the commands shown above.
116+
Creation of virtual environments is done through the :mod:`venv` module.
117+
Installing packages into an active virtual environment uses the commands shown
118+
above.
105119

106120
.. seealso::
107121

108122
`Python Packaging User Guide: Installing Python Distribution Packages
109-
<https://packaging.python.org/en/latest/installing/>`__
123+
<https://packaging.python.org/installing/>`__
110124

111125

112126
How do I ...?
@@ -124,7 +138,7 @@ User Guide.
124138
.. seealso::
125139

126140
`Python Packaging User Guide: Requirements for Installing Packages
127-
<https://packaging.python.org/en/latest/installing/#requirements-for-installing-packages>`__
141+
<https://packaging.python.org/installing/#requirements-for-installing-packages>`__
128142

129143

130144
.. installing-per-user-installation:
@@ -142,20 +156,19 @@ package just for the current user, rather than for all users of the system.
142156
A number of scientific Python packages have complex binary dependencies, and
143157
aren't currently easy to install using ``pip`` directly. At this point in
144158
time, it will often be easier for users to install these packages by
145-
`other means
146-
<https://packaging.python.org/en/latest/science/>`__
159+
`other means <https://packaging.python.org/science/>`__
147160
rather than attempting to install them with ``pip``.
148161

149162
.. seealso::
150163

151164
`Python Packaging User Guide: Installing Scientific Packages
152-
<https://packaging.python.org/en/latest/science/>`__
165+
<https://packaging.python.org/science/>`__
153166

154167

155168
... work with multiple versions of Python installed in parallel?
156169
----------------------------------------------------------------
157170

158-
On Linux, Mac OS X and other POSIX systems, use the versioned Python commands
171+
On Linux, Mac OS X, and other POSIX systems, use the versioned Python commands
159172
in combination with the ``-m`` switch to run the appropriate copy of
160173
``pip``::
161174

@@ -164,7 +177,7 @@ in combination with the ``-m`` switch to run the appropriate copy of
164177
python3 -m pip install SomePackage # default Python 3
165178
python3.4 -m pip install SomePackage # specifically Python 3.4
166179

167-
(appropriately versioned ``pip`` commands may also be available)
180+
Appropriately versioned ``pip`` commands may also be available.
168181

169182
On Windows, use the ``py`` Python launcher in combination with the ``-m``
170183
switch::
@@ -212,11 +225,11 @@ as users are more regularly able to install pre-built extensions rather
212225
than needing to build them themselves.
213226

214227
Some of the solutions for installing `scientific software
215-
<https://packaging.python.org/en/latest/science/>`__
216-
that is not yet available as pre-built ``wheel`` files may also help with
228+
<https://packaging.python.org/science/>`__
229+
that are not yet available as pre-built ``wheel`` files may also help with
217230
obtaining other binary extensions without needing to build them locally.
218231

219232
.. seealso::
220233

221234
`Python Packaging User Guide: Binary Extensions
222-
<https://packaging.python.org/en/latest/extensions/>`__
235+
<https://packaging.python.org/extensions/>`__

Doc/library/venv.rst

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,50 @@ Creating virtual environments
3131

3232
.. _venv-def:
3333

34-
.. note:: A virtual environment (also called a ``venv``) is a Python
35-
environment such that the Python interpreter, libraries and scripts
36-
installed into it are isolated from those installed in other virtual
37-
environments, and (by default) any libraries installed in a "system" Python,
38-
i.e. one which is installed as part of your operating system.
34+
.. note:: A virtual environment is a Python environment such that the Python
35+
interpreter, libraries and scripts installed into it are isolated from those
36+
installed in other virtual environments, and (by default) any libraries
37+
installed in a "system" Python, i.e., one which is installed as part of your
38+
operating system.
3939

40-
A venv is a directory tree which contains Python executable files and
41-
other files which indicate that it is a venv.
40+
A virtual environment is a directory tree which contains Python executable
41+
files and other files which indicate that it is a virtual environment.
4242

4343
Common installation tools such as ``Setuptools`` and ``pip`` work as
44-
expected with venvs - i.e. when a venv is active, they install Python
45-
packages into the venv without needing to be told to do so explicitly.
46-
47-
When a venv is active (i.e. the venv's Python interpreter is running), the
48-
attributes :attr:`sys.prefix` and :attr:`sys.exec_prefix` point to the base
49-
directory of the venv, whereas :attr:`sys.base_prefix` and
50-
:attr:`sys.base_exec_prefix` point to the non-venv Python installation
51-
which was used to create the venv. If a venv is not active, then
52-
:attr:`sys.prefix` is the same as :attr:`sys.base_prefix` and
53-
:attr:`sys.exec_prefix` is the same as :attr:`sys.base_exec_prefix` (they
54-
all point to a non-venv Python installation).
55-
56-
When a venv is active, any options that change the installation path will be
57-
ignored from all distutils configuration files to prevent projects being
58-
inadvertently installed outside of the virtual environment.
59-
60-
When working in a command shell, users can make a venv active by running an
61-
``activate`` script in the venv's executables directory (the precise filename
62-
is shell-dependent), which prepends the venv's directory for executables to
63-
the ``PATH`` environment variable for the running shell. There should be no
64-
need in other circumstances to activate a venv -- scripts installed into
65-
venvs have a shebang line which points to the venv's Python interpreter. This
66-
means that the script will run with that interpreter regardless of the value
67-
of ``PATH``. On Windows, shebang line processing is supported if you have the
68-
Python Launcher for Windows installed (this was added to Python in 3.3 - see
69-
:pep:`397` for more details). Thus, double-clicking an installed script in
70-
a Windows Explorer window should run the script with the correct interpreter
71-
without there needing to be any reference to its venv in ``PATH``.
44+
expected with virtual environments. In other words, when a virtual
45+
environment is active, they install Python packages into the virtual
46+
environment without needing to be told to do so explicitly.
47+
48+
When a virtual environment is active (i.e., the virtual environment's Python
49+
interpreter is running), the attributes :attr:`sys.prefix` and
50+
:attr:`sys.exec_prefix` point to the base directory of the virtual
51+
environment, whereas :attr:`sys.base_prefix` and
52+
:attr:`sys.base_exec_prefix` point to the non-virtual environment Python
53+
installation which was used to create the virtual environment. If a virtual
54+
environment is not active, then :attr:`sys.prefix` is the same as
55+
:attr:`sys.base_prefix` and :attr:`sys.exec_prefix` is the same as
56+
:attr:`sys.base_exec_prefix` (they all point to a non-virtual environment
57+
Python installation).
58+
59+
When a virtual environment is active, any options that change the
60+
installation path will be ignored from all distutils configuration files to
61+
prevent projects being inadvertently installed outside of the virtual
62+
environment.
63+
64+
When working in a command shell, users can make a virtual environment active
65+
by running an ``activate`` script in the virtual environment's executables
66+
directory (the precise filename is shell-dependent), which prepends the
67+
virtual environment's directory for executables to the ``PATH`` environment
68+
variable for the running shell. There should be no need in other
69+
circumstances to activate a virtual environment—scripts installed into
70+
virtual environments have a "shebang" line which points to the virtual
71+
environment's Python interpreter. This means that the script will run with
72+
that interpreter regardless of the value of ``PATH``. On Windows, "shebang"
73+
line processing is supported if you have the Python Launcher for Windows
74+
installed (this was added to Python in 3.3 - see :pep:`397` for more
75+
details). Thus, double-clicking an installed script in a Windows Explorer
76+
window should run the script with the correct interpreter without there
77+
needing to be any reference to its virtual environment in ``PATH``.
7278

7379

7480
.. _venv-api:
@@ -219,7 +225,7 @@ An example of extending ``EnvBuilder``
219225
--------------------------------------
220226

221227
The following script shows how to extend :class:`EnvBuilder` by implementing a
222-
subclass which installs setuptools and pip into a created venv::
228+
subclass which installs setuptools and pip into a created virtual environment::
223229

224230
import os
225231
import os.path
@@ -233,12 +239,12 @@ subclass which installs setuptools and pip into a created venv::
233239
class ExtendedEnvBuilder(venv.EnvBuilder):
234240
"""
235241
This builder installs setuptools and pip so that you can pip or
236-
easy_install other packages into the created environment.
242+
easy_install other packages into the created virtual environment.
237243

238244
:param nodist: If True, setuptools and pip are not installed into the
239-
created environment.
245+
created virtual environment.
240246
:param nopip: If True, pip is not installed into the created
241-
environment.
247+
virtual environment.
242248
:param progress: If setuptools or pip are installed, the progress of the
243249
installation can be monitored by passing a progress
244250
callable. If specified, it is called with two
@@ -264,10 +270,10 @@ subclass which installs setuptools and pip into a created venv::
264270
def post_setup(self, context):
265271
"""
266272
Set up any packages which need to be pre-installed into the
267-
environment being created.
273+
virtual environment being created.
268274

269-
:param context: The information for the environment creation request
270-
being processed.
275+
:param context: The information for the virtual environment
276+
creation request being processed.
271277
"""
272278
os.environ['VIRTUAL_ENV'] = context.env_dir
273279
if not self.nodist:
@@ -301,7 +307,7 @@ subclass which installs setuptools and pip into a created venv::
301307
fn = os.path.split(path)[-1]
302308
binpath = context.bin_path
303309
distpath = os.path.join(binpath, fn)
304-
# Download script into the env's binaries folder
310+
# Download script into the virtual environment's binaries folder
305311
urlretrieve(url, distpath)
306312
progress = self.progress
307313
if self.verbose:
@@ -313,7 +319,7 @@ subclass which installs setuptools and pip into a created venv::
313319
else:
314320
sys.stderr.write('Installing %s ...%s' % (name, term))
315321
sys.stderr.flush()
316-
# Install in the env
322+
# Install in the virtual environment
317323
args = [context.env_exe, fn]
318324
p = Popen(args, stdout=PIPE, stderr=PIPE, cwd=binpath)
319325
t1 = Thread(target=self.reader, args=(p.stdout, 'stdout'))
@@ -332,10 +338,10 @@ subclass which installs setuptools and pip into a created venv::
332338

333339
def install_setuptools(self, context):
334340
"""
335-
Install setuptools in the environment.
341+
Install setuptools in the virtual environment.
336342

337-
:param context: The information for the environment creation request
338-
being processed.
343+
:param context: The information for the virtual environment
344+
creation request being processed.
339345
"""
340346
url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py'
341347
self.install_script(context, 'setuptools', url)
@@ -348,10 +354,10 @@ subclass which installs setuptools and pip into a created venv::
348354

349355
def install_pip(self, context):
350356
"""
351-
Install pip in the environment.
357+
Install pip in the virtual environment.
352358

353-
:param context: The information for the environment creation request
354-
being processed.
359+
:param context: The information for the virtual environment
360+
creation request being processed.
355361
"""
356362
url = 'https://raw.github.com/pypa/pip/master/contrib/get-pip.py'
357363
self.install_script(context, 'pip', url)
@@ -374,7 +380,8 @@ subclass which installs setuptools and pip into a created venv::
374380
'more target '
375381
'directories.')
376382
parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
377-
help='A directory to create the environment in.')
383+
help='A directory in which to create the
384+
'virtual environment.')
378385
parser.add_argument('--no-setuptools', default=False,
379386
action='store_true', dest='nodist',
380387
help="Don't install setuptools or pip in the "
@@ -398,14 +405,17 @@ subclass which installs setuptools and pip into a created venv::
398405
'the platform.')
399406
parser.add_argument('--clear', default=False, action='store_true',
400407
dest='clear', help='Delete the contents of the '
401-
'environment directory if it '
402-
'already exists, before '
408+
'virtual environment '
409+
'directory if it already '
410+
'exists, before virtual '
403411
'environment creation.')
404412
parser.add_argument('--upgrade', default=False, action='store_true',
405-
dest='upgrade', help='Upgrade the environment '
406-
'directory to use this version '
407-
'of Python, assuming Python '
408-
'has been upgraded in-place.')
413+
dest='upgrade', help='Upgrade the virtual '
414+
'environment directory to '
415+
'use this version of '
416+
'Python, assuming Python '
417+
'has been upgraded '
418+
'in-place.')
409419
parser.add_argument('--verbose', default=False, action='store_true',
410420
dest='verbose', help='Display the output '
411421
'from the scripts which '

0 commit comments

Comments
 (0)