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

Skip to content

Commit c4618e3

Browse files
committed
Factored out common venv documentation and added more information about Distribute/pip.
1 parent 7d39055 commit c4618e3

3 files changed

Lines changed: 93 additions & 167 deletions

File tree

Doc/library/venv.rst

Lines changed: 7 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -25,88 +25,8 @@ independent set of installed Python packages in its site directories.
2525
Creating 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

Doc/using/scripts.rst

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,5 @@ Additional Tools and Scripts
66
pyvenv - Creating virtual environments
77
--------------------------------------
88

9-
Creation of :ref:`virtual environments <venv-def>` is done by executing the
10-
``pyvenv`` script::
11-
12-
pyvenv /path/to/new/virtual/environment
13-
14-
Running this command creates the target directory (creating any parent
15-
directories that don't exist already) and places a ``pyvenv.cfg`` file
16-
in it with a ``home`` key pointing to the Python installation the
17-
command was run from. It also creates a ``bin`` (or ``Scripts`` on
18-
Windows) subdirectory containing a copy of the ``python`` binary (or
19-
binaries, in the case of Windows).
20-
It also creates an (initially empty) ``lib/pythonX.Y/site-packages``
21-
subdirectory (on Windows, this is ``Lib\site-packages``).
22-
23-
.. highlight:: none
24-
25-
On Windows, you may have to invoke the ``pyvenv`` script as follows, if you
26-
don't have the relevant PATH and PATHEXT settings::
27-
28-
c:\Temp>c:\Python33\python c:\Python33\Tools\Scripts\pyvenv.py myenv
29-
30-
or equivalently::
31-
32-
c:\Temp>c:\Python33\python -m venv myenv
33-
34-
The command, if run with ``-h``, will show the available options::
35-
36-
usage: pyvenv [-h] [--system-site-packages] [--symlinks] [--clear]
37-
[--upgrade] ENV_DIR [ENV_DIR ...]
38-
39-
Creates virtual Python environments in one or more target directories.
40-
41-
positional arguments:
42-
ENV_DIR A directory to create the environment in.
43-
44-
optional arguments:
45-
-h, --help show this help message and exit
46-
--system-site-packages Give access to the global site-packages dir to the
47-
virtual environment.
48-
--symlinks Try to use symlinks rather than copies, when symlinks
49-
are not the default for the platform.
50-
--clear Delete the environment directory if it already exists.
51-
If not specified and the directory exists, an error is
52-
raised.
53-
--upgrade Upgrade the environment directory to use this version
54-
of Python, assuming Python has been upgraded in-place.
55-
56-
If the target directory already exists an error will be raised, unless
57-
the ``--clear`` or ``--upgrade`` option was provided.
58-
59-
The created ``pyvenv.cfg`` file also includes the
60-
``include-system-site-packages`` key, set to ``true`` if ``venv`` is
61-
run with the ``--system-site-packages`` option, ``false`` otherwise.
62-
63-
Multiple paths can be given to ``pyvenv``, in which case an identical
64-
virtualenv will be created, according to the given options, at each
65-
provided path.
66-
67-
Once a venv has been created, it can be "activated" using a script in the
68-
venv's binary directory. The invocation of the script is platform-specific: on
69-
a Posix platform, you would typically do::
70-
71-
$ source <venv>/bin/activate
72-
73-
whereas on Windows, you might do::
74-
75-
C:\> <venv>/Scripts/activate
76-
77-
if you are using the ``cmd.exe`` shell, or perhaps::
78-
79-
PS C:\> <venv>/Scripts/Activate.ps1
80-
81-
if you use PowerShell.
82-
83-
You don't specifically *need* to activate an environment; activation just
84-
prepends the venv's binary directory to your path, so that "python" invokes the
85-
venv's Python interpreter and you can run installed scripts without having to
86-
use their full path. However, all scripts installed in a venv should be
87-
runnable without activating it, and run with the venv's Python automatically.
88-
89-
You can deactivate a venv by typing "deactivate" in your shell. The exact
90-
mechanism is platform-specific: for example, the Bash activation script defines
91-
a "deactivate" function, whereas on Windows there are separate scripts called
92-
``deactivate.bat`` and ``Deactivate.ps1`` which are installed when the venv is
93-
created.
9+
.. include:: venv-create.inc
9410

Doc/using/venv-create.inc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Creation of :ref:`virtual environments <venv-def>` is done by executing the
2+
``pyvenv`` script::
3+
4+
pyvenv /path/to/new/virtual/environment
5+
6+
Running this command creates the target directory (creating any parent
7+
directories that don't exist already) and places a ``pyvenv.cfg`` file in it
8+
with a ``home`` key pointing to the Python installation the command was run
9+
from. It also creates a ``bin`` (or ``Scripts`` on Windows) subdirectory
10+
containing a copy of the ``python`` binary (or binaries, in the case of
11+
Windows). It also creates an (initially empty) ``lib/pythonX.Y/site-packages``
12+
subdirectory (on Windows, this is ``Lib\site-packages``).
13+
14+
.. highlight:: none
15+
16+
On Windows, you may have to invoke the ``pyvenv`` script as follows, if you
17+
don't have the relevant PATH and PATHEXT settings::
18+
19+
c:\Temp>c:\Python33\python c:\Python33\Tools\Scripts\pyvenv.py myenv
20+
21+
or equivalently::
22+
23+
c:\Temp>c:\Python33\python -m venv myenv
24+
25+
The command, if run with ``-h``, will show the available options::
26+
27+
usage: pyvenv [-h] [--system-site-packages] [--symlinks] [--clear]
28+
[--upgrade] ENV_DIR [ENV_DIR ...]
29+
30+
Creates virtual Python environments in one or more target directories.
31+
32+
positional arguments:
33+
ENV_DIR A directory to create the environment in.
34+
35+
optional arguments:
36+
-h, --help show this help message and exit
37+
--system-site-packages Give access to the global site-packages dir to the
38+
virtual environment.
39+
--symlinks Try to use symlinks rather than copies, when symlinks
40+
are not the default for the platform.
41+
--clear Delete the environment directory if it already exists.
42+
If not specified and the directory exists, an error is
43+
raised.
44+
--upgrade Upgrade the environment directory to use this version
45+
of Python, assuming Python has been upgraded in-place.
46+
47+
If the target directory already exists an error will be raised, unless
48+
the ``--clear`` or ``--upgrade`` option was provided.
49+
50+
The created ``pyvenv.cfg`` file also includes the
51+
``include-system-site-packages`` key, set to ``true`` if ``venv`` is
52+
run with the ``--system-site-packages`` option, ``false`` otherwise.
53+
54+
Multiple paths can be given to ``pyvenv``, in which case an identical
55+
virtualenv will be created, according to the given options, at each
56+
provided path.
57+
58+
Once a venv has been created, it can be "activated" using a script in the
59+
venv's binary directory. The invocation of the script is platform-specific: on
60+
a Posix platform, you would typically do::
61+
62+
$ source <venv>/bin/activate
63+
64+
whereas on Windows, you might do::
65+
66+
C:\> <venv>/Scripts/activate
67+
68+
if you are using the ``cmd.exe`` shell, or perhaps::
69+
70+
PS C:\> <venv>/Scripts/Activate.ps1
71+
72+
if you use PowerShell.
73+
74+
You don't specifically *need* to activate an environment; activation just
75+
prepends the venv's binary directory to your path, so that "python" invokes the
76+
venv's Python interpreter and you can run installed scripts without having to
77+
use their full path. However, all scripts installed in a venv should be
78+
runnable without activating it, and run with the venv's Python automatically.
79+
80+
You can deactivate a venv by typing "deactivate" in your shell. The exact
81+
mechanism is platform-specific: for example, the Bash activation script defines
82+
a "deactivate" function, whereas on Windows there are separate scripts called
83+
``deactivate.bat`` and ``Deactivate.ps1`` which are installed when the venv is
84+
created.
85+

0 commit comments

Comments
 (0)