@@ -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
221227The 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