@@ -25,88 +25,8 @@ independent set of installed Python packages in its site directories.
2525Creating virtual environments
2626-----------------------------
2727
28- Creation of virtual environments is simplest executing the `` pyvenv `` script::
28+ .. include :: /using/venv-create.inc
2929
30- pyvenv /path/to/new/virtual/environment
31-
32- Running this command creates the target directory (creating any parent
33- directories that don't exist already) and places a ``pyvenv.cfg `` file in it
34- with a ``home `` key pointing to the Python installation the command was run
35- from. It also creates a ``bin `` (or ``Scripts `` on Windows) subdirectory
36- containing a copy of the ``python `` binary (or binaries, in the case of
37- Windows). It also creates an (initially empty) ``lib/pythonX.Y/site-packages ``
38- subdirectory (on Windows, this is ``Lib\site-packages ``).
39-
40- .. highlight :: none
41-
42- On Windows, you may have to invoke the ``pyvenv `` script as follows, if you
43- don't have the relevant PATH and PATHEXT settings::
44-
45- c:\Temp>c:\Python33\python c:\Python33\Tools\Scripts\pyvenv.py myenv
46-
47- or equivalently::
48-
49- c:\Temp>c:\Python33\python -m venv myenv
50-
51- The command, if run with ``-h ``, will show the available options::
52-
53- usage: pyvenv [-h] [--system-site-packages] [--symlinks] [--clear]
54- [--upgrade] ENV_DIR [ENV_DIR ...]
55-
56- Creates virtual Python environments in one or more target directories.
57-
58- positional arguments:
59- ENV_DIR A directory to create the environment in.
60-
61- optional arguments:
62- -h, --help show this help message and exit
63- --system-site-packages Give access to the global site-packages dir to the
64- virtual environment.
65- --symlinks Try to use symlinks rather than copies, when symlinks
66- are not the default for the platform.
67- --clear Delete the environment directory if it already exists.
68- If not specified and the directory exists, an error is
69- raised.
70- --upgrade Upgrade the environment directory to use this version
71- of Python, assuming Python has been upgraded in-place.
72-
73- If the target directory already exists an error will be raised, unless the
74- ``--clear `` or ``--upgrade `` option was provided.
75-
76- The created ``pyvenv.cfg `` file also includes the
77- ``include-system-site-packages `` key, set to ``true `` if ``venv `` is run with
78- the ``--system-site-packages `` option, ``false `` otherwise.
79-
80- Multiple paths can be given to ``pyvenv ``, in which case an identical virtualenv
81- will be created, according to the given options, at each provided path.
82-
83- Once a venv has been created, it can be "activated" using a script in the
84- venv's binary directory. The invocation of the script is platform-specific: on
85- a Posix platform, you would typically do::
86-
87- $ source <venv>/bin/activate
88-
89- whereas on Windows, you might do::
90-
91- C:\> <venv>/Scripts/activate
92-
93- if you are using the ``cmd.exe `` shell, or perhaps::
94-
95- PS C:\> <venv>/Scripts/Activate.ps1
96-
97- if you use PowerShell.
98-
99- You don't specifically *need * to activate an environment; activation just
100- prepends the venv's binary directory to your path, so that "python" invokes the
101- venv's Python interpreter and you can run installed scripts without having to
102- use their full path. However, all scripts installed in a venv should be
103- runnable without activating it, and run with the venv's Python automatically.
104-
105- You can deactivate a venv by typing "deactivate" in your shell. The exact
106- mechanism is platform-specific: for example, the Bash activation script defines
107- a "deactivate" function, whereas on Windows there are separate scripts called
108- ``deactivate.bat `` and ``Deactivate.ps1 `` which are installed when the venv is
109- created.
11030
11131.. _venv-def :
11232
@@ -119,9 +39,14 @@ created.
11939 A venv is a directory tree which contains Python executable files and
12040 other files which indicate that it is a venv.
12141
122- Common installation tools such as ``distribute `` and ``pip `` work as
42+ Common installation tools such as ``Distribute `` and ``pip `` work as
12343 expected with venvs - i.e. when a venv is active, they install Python
12444 packages into the venv without needing to be told to do so explicitly.
45+ Of course, you need to install them into the venv first: this could be
46+ done by running ``distribute_setup.py `` with the venv activated,
47+ followed by running ``easy_install pip ``. Alternatively, you could download
48+ the source tarballs and run ``python setup.py install `` after unpacking,
49+ with the venv activated.
12550
12651 When a venv is active (i.e. the venv's Python interpreter is running), the
12752 attributes :attr: `sys.prefix ` and :attr: `sys.exec_prefix ` point to the base
0 commit comments