mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-31 09:42:27 +00:00
python-3.6.zip added from Github
README.cosmo contains the necessary links.
This commit is contained in:
parent
75fc601ff5
commit
0c4c56ff39
4219 changed files with 1968626 additions and 0 deletions
745
third_party/python/Doc/using/cmdline.rst
vendored
Normal file
745
third_party/python/Doc/using/cmdline.rst
vendored
Normal file
|
@ -0,0 +1,745 @@
|
|||
.. highlightlang:: sh
|
||||
|
||||
.. ATTENTION: You probably should update Misc/python.man, too, if you modify
|
||||
this file.
|
||||
|
||||
.. _using-on-general:
|
||||
|
||||
Command line and environment
|
||||
============================
|
||||
|
||||
The CPython interpreter scans the command line and the environment for various
|
||||
settings.
|
||||
|
||||
.. impl-detail::
|
||||
|
||||
Other implementations' command line schemes may differ. See
|
||||
:ref:`implementations` for further resources.
|
||||
|
||||
|
||||
.. _using-on-cmdline:
|
||||
|
||||
Command line
|
||||
------------
|
||||
|
||||
When invoking Python, you may specify any of these options::
|
||||
|
||||
python [-bBdEhiIOqsSuvVWx?] [-c command | -m module-name | script | - ] [args]
|
||||
|
||||
The most common use case is, of course, a simple invocation of a script::
|
||||
|
||||
python myscript.py
|
||||
|
||||
|
||||
.. _using-on-interface-options:
|
||||
|
||||
Interface options
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
The interpreter interface resembles that of the UNIX shell, but provides some
|
||||
additional methods of invocation:
|
||||
|
||||
* When called with standard input connected to a tty device, it prompts for
|
||||
commands and executes them until an EOF (an end-of-file character, you can
|
||||
produce that with :kbd:`Ctrl-D` on UNIX or :kbd:`Ctrl-Z, Enter` on Windows) is read.
|
||||
* When called with a file name argument or with a file as standard input, it
|
||||
reads and executes a script from that file.
|
||||
* When called with a directory name argument, it reads and executes an
|
||||
appropriately named script from that directory.
|
||||
* When called with ``-c command``, it executes the Python statement(s) given as
|
||||
*command*. Here *command* may contain multiple statements separated by
|
||||
newlines. Leading whitespace is significant in Python statements!
|
||||
* When called with ``-m module-name``, the given module is located on the
|
||||
Python module path and executed as a script.
|
||||
|
||||
In non-interactive mode, the entire input is parsed before it is executed.
|
||||
|
||||
An interface option terminates the list of options consumed by the interpreter,
|
||||
all consecutive arguments will end up in :data:`sys.argv` -- note that the first
|
||||
element, subscript zero (``sys.argv[0]``), is a string reflecting the program's
|
||||
source.
|
||||
|
||||
.. cmdoption:: -c <command>
|
||||
|
||||
Execute the Python code in *command*. *command* can be one or more
|
||||
statements separated by newlines, with significant leading whitespace as in
|
||||
normal module code.
|
||||
|
||||
If this option is given, the first element of :data:`sys.argv` will be
|
||||
``"-c"`` and the current directory will be added to the start of
|
||||
:data:`sys.path` (allowing modules in that directory to be imported as top
|
||||
level modules).
|
||||
|
||||
|
||||
.. cmdoption:: -m <module-name>
|
||||
|
||||
Search :data:`sys.path` for the named module and execute its contents as
|
||||
the :mod:`__main__` module.
|
||||
|
||||
Since the argument is a *module* name, you must not give a file extension
|
||||
(``.py``). The module name should be a valid absolute Python module name, but
|
||||
the implementation may not always enforce this (e.g. it may allow you to
|
||||
use a name that includes a hyphen).
|
||||
|
||||
Package names (including namespace packages) are also permitted. When a
|
||||
package name is supplied instead
|
||||
of a normal module, the interpreter will execute ``<pkg>.__main__`` as
|
||||
the main module. This behaviour is deliberately similar to the handling
|
||||
of directories and zipfiles that are passed to the interpreter as the
|
||||
script argument.
|
||||
|
||||
.. note::
|
||||
|
||||
This option cannot be used with built-in modules and extension modules
|
||||
written in C, since they do not have Python module files. However, it
|
||||
can still be used for precompiled modules, even if the original source
|
||||
file is not available.
|
||||
|
||||
If this option is given, the first element of :data:`sys.argv` will be the
|
||||
full path to the module file (while the module file is being located, the
|
||||
first element will be set to ``"-m"``). As with the :option:`-c` option,
|
||||
the current directory will be added to the start of :data:`sys.path`.
|
||||
|
||||
Many standard library modules contain code that is invoked on their execution
|
||||
as a script. An example is the :mod:`timeit` module::
|
||||
|
||||
python -mtimeit -s 'setup here' 'benchmarked code here'
|
||||
python -mtimeit -h # for details
|
||||
|
||||
.. seealso::
|
||||
:func:`runpy.run_module`
|
||||
Equivalent functionality directly available to Python code
|
||||
|
||||
:pep:`338` -- Executing modules as scripts
|
||||
|
||||
|
||||
.. versionchanged:: 3.1
|
||||
Supply the package name to run a ``__main__`` submodule.
|
||||
|
||||
.. versionchanged:: 3.4
|
||||
namespace packages are also supported
|
||||
|
||||
|
||||
.. describe:: -
|
||||
|
||||
Read commands from standard input (:data:`sys.stdin`). If standard input is
|
||||
a terminal, :option:`-i` is implied.
|
||||
|
||||
If this option is given, the first element of :data:`sys.argv` will be
|
||||
``"-"`` and the current directory will be added to the start of
|
||||
:data:`sys.path`.
|
||||
|
||||
|
||||
.. describe:: <script>
|
||||
|
||||
Execute the Python code contained in *script*, which must be a filesystem
|
||||
path (absolute or relative) referring to either a Python file, a directory
|
||||
containing a ``__main__.py`` file, or a zipfile containing a
|
||||
``__main__.py`` file.
|
||||
|
||||
If this option is given, the first element of :data:`sys.argv` will be the
|
||||
script name as given on the command line.
|
||||
|
||||
If the script name refers directly to a Python file, the directory
|
||||
containing that file is added to the start of :data:`sys.path`, and the
|
||||
file is executed as the :mod:`__main__` module.
|
||||
|
||||
If the script name refers to a directory or zipfile, the script name is
|
||||
added to the start of :data:`sys.path` and the ``__main__.py`` file in
|
||||
that location is executed as the :mod:`__main__` module.
|
||||
|
||||
.. seealso::
|
||||
:func:`runpy.run_path`
|
||||
Equivalent functionality directly available to Python code
|
||||
|
||||
|
||||
If no interface option is given, :option:`-i` is implied, ``sys.argv[0]`` is
|
||||
an empty string (``""``) and the current directory will be added to the
|
||||
start of :data:`sys.path`. Also, tab-completion and history editing is
|
||||
automatically enabled, if available on your platform (see
|
||||
:ref:`rlcompleter-config`).
|
||||
|
||||
.. seealso:: :ref:`tut-invoking`
|
||||
|
||||
.. versionchanged:: 3.4
|
||||
Automatic enabling of tab-completion and history editing.
|
||||
|
||||
|
||||
Generic options
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
.. cmdoption:: -?
|
||||
-h
|
||||
--help
|
||||
|
||||
Print a short description of all command line options.
|
||||
|
||||
|
||||
.. cmdoption:: -V
|
||||
--version
|
||||
|
||||
Print the Python version number and exit. Example output could be:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
Python 3.6.0b2+
|
||||
|
||||
When given twice, print more information about the build, like:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
Python 3.6.0b2+ (3.6:84a3c5003510+, Oct 26 2016, 02:33:55)
|
||||
[GCC 6.2.0 20161005]
|
||||
|
||||
.. versionadded:: 3.6
|
||||
The ``-VV`` option.
|
||||
|
||||
.. _using-on-misc-options:
|
||||
|
||||
Miscellaneous options
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. cmdoption:: -b
|
||||
|
||||
Issue a warning when comparing :class:`bytes` or :class:`bytearray` with
|
||||
:class:`str` or :class:`bytes` with :class:`int`. Issue an error when the
|
||||
option is given twice (:option:`!-bb`).
|
||||
|
||||
.. versionchanged:: 3.5
|
||||
Affects comparisons of :class:`bytes` with :class:`int`.
|
||||
|
||||
.. cmdoption:: -B
|
||||
|
||||
If given, Python won't try to write ``.pyc`` files on the
|
||||
import of source modules. See also :envvar:`PYTHONDONTWRITEBYTECODE`.
|
||||
|
||||
|
||||
.. cmdoption:: -d
|
||||
|
||||
Turn on parser debugging output (for wizards only, depending on compilation
|
||||
options). See also :envvar:`PYTHONDEBUG`.
|
||||
|
||||
|
||||
.. cmdoption:: -E
|
||||
|
||||
Ignore all :envvar:`PYTHON*` environment variables, e.g.
|
||||
:envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`, that might be set.
|
||||
|
||||
|
||||
.. cmdoption:: -i
|
||||
|
||||
When a script is passed as first argument or the :option:`-c` option is used,
|
||||
enter interactive mode after executing the script or the command, even when
|
||||
:data:`sys.stdin` does not appear to be a terminal. The
|
||||
:envvar:`PYTHONSTARTUP` file is not read.
|
||||
|
||||
This can be useful to inspect global variables or a stack trace when a script
|
||||
raises an exception. See also :envvar:`PYTHONINSPECT`.
|
||||
|
||||
|
||||
.. cmdoption:: -I
|
||||
|
||||
Run Python in isolated mode. This also implies -E and -s.
|
||||
In isolated mode :data:`sys.path` contains neither the script's directory nor
|
||||
the user's site-packages directory. All :envvar:`PYTHON*` environment
|
||||
variables are ignored, too. Further restrictions may be imposed to prevent
|
||||
the user from injecting malicious code.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
.. cmdoption:: -O
|
||||
|
||||
Remove assert statements and any code conditional on the value of
|
||||
:const:`__debug__`. Augment the filename for compiled
|
||||
(:term:`bytecode`) files by adding ``.opt-1`` before the ``.pyc``
|
||||
extension (see :pep:`488`). See also :envvar:`PYTHONOPTIMIZE`.
|
||||
|
||||
.. versionchanged:: 3.5
|
||||
Modify ``.pyc`` filenames according to :pep:`488`.
|
||||
|
||||
|
||||
.. cmdoption:: -OO
|
||||
|
||||
Do :option:`-O` and also discard docstrings. Augment the filename
|
||||
for compiled (:term:`bytecode`) files by adding ``.opt-2`` before the
|
||||
``.pyc`` extension (see :pep:`488`).
|
||||
|
||||
.. versionchanged:: 3.5
|
||||
Modify ``.pyc`` filenames according to :pep:`488`.
|
||||
|
||||
|
||||
.. cmdoption:: -q
|
||||
|
||||
Don't display the copyright and version messages even in interactive mode.
|
||||
|
||||
.. versionadded:: 3.2
|
||||
|
||||
|
||||
.. cmdoption:: -R
|
||||
|
||||
Kept for compatibility. On Python 3.3 and greater, hash randomization is
|
||||
turned on by default.
|
||||
|
||||
On previous versions of Python, this option turns on hash randomization,
|
||||
so that the :meth:`__hash__` values of str, bytes and datetime
|
||||
are "salted" with an unpredictable random value. Although they remain
|
||||
constant within an individual Python process, they are not predictable
|
||||
between repeated invocations of Python.
|
||||
|
||||
Hash randomization is intended to provide protection against a
|
||||
denial-of-service caused by carefully-chosen inputs that exploit the worst
|
||||
case performance of a dict construction, O(n^2) complexity. See
|
||||
http://www.ocert.org/advisories/ocert-2011-003.html for details.
|
||||
|
||||
:envvar:`PYTHONHASHSEED` allows you to set a fixed value for the hash
|
||||
seed secret.
|
||||
|
||||
.. versionadded:: 3.2.3
|
||||
|
||||
|
||||
.. cmdoption:: -s
|
||||
|
||||
Don't add the :data:`user site-packages directory <site.USER_SITE>` to
|
||||
:data:`sys.path`.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:pep:`370` -- Per user site-packages directory
|
||||
|
||||
|
||||
.. cmdoption:: -S
|
||||
|
||||
Disable the import of the module :mod:`site` and the site-dependent
|
||||
manipulations of :data:`sys.path` that it entails. Also disable these
|
||||
manipulations if :mod:`site` is explicitly imported later (call
|
||||
:func:`site.main` if you want them to be triggered).
|
||||
|
||||
|
||||
.. cmdoption:: -u
|
||||
|
||||
Force the binary layer of the stdout and stderr streams (which is
|
||||
available as their ``buffer`` attribute) to be unbuffered. The text I/O
|
||||
layer will still be line-buffered if writing to the console, or
|
||||
block-buffered if redirected to a non-interactive file.
|
||||
|
||||
See also :envvar:`PYTHONUNBUFFERED`.
|
||||
|
||||
|
||||
.. cmdoption:: -v
|
||||
|
||||
Print a message each time a module is initialized, showing the place
|
||||
(filename or built-in module) from which it is loaded. When given twice
|
||||
(:option:`!-vv`), print a message for each file that is checked for when
|
||||
searching for a module. Also provides information on module cleanup at exit.
|
||||
See also :envvar:`PYTHONVERBOSE`.
|
||||
|
||||
|
||||
.. _using-on-warnings:
|
||||
.. cmdoption:: -W arg
|
||||
|
||||
Warning control. Python's warning machinery by default prints warning
|
||||
messages to :data:`sys.stderr`. A typical warning message has the following
|
||||
form:
|
||||
|
||||
.. code-block:: none
|
||||
|
||||
file:line: category: message
|
||||
|
||||
By default, each warning is printed once for each source line where it
|
||||
occurs. This option controls how often warnings are printed.
|
||||
|
||||
Multiple :option:`-W` options may be given; when a warning matches more than
|
||||
one option, the action for the last matching option is performed. Invalid
|
||||
:option:`-W` options are ignored (though, a warning message is printed about
|
||||
invalid options when the first warning is issued).
|
||||
|
||||
Warnings can also be controlled from within a Python program using the
|
||||
:mod:`warnings` module.
|
||||
|
||||
The simplest form of argument is one of the following action strings (or a
|
||||
unique abbreviation):
|
||||
|
||||
``ignore``
|
||||
Ignore all warnings.
|
||||
``default``
|
||||
Explicitly request the default behavior (printing each warning once per
|
||||
source line).
|
||||
``all``
|
||||
Print a warning each time it occurs (this may generate many messages if a
|
||||
warning is triggered repeatedly for the same source line, such as inside a
|
||||
loop).
|
||||
``module``
|
||||
Print each warning only the first time it occurs in each module.
|
||||
``once``
|
||||
Print each warning only the first time it occurs in the program.
|
||||
``error``
|
||||
Raise an exception instead of printing a warning message.
|
||||
|
||||
The full form of argument is::
|
||||
|
||||
action:message:category:module:line
|
||||
|
||||
Here, *action* is as explained above but only applies to messages that match
|
||||
the remaining fields. Empty fields match all values; trailing empty fields
|
||||
may be omitted. The *message* field matches the start of the warning message
|
||||
printed; this match is case-insensitive. The *category* field matches the
|
||||
warning category. This must be a class name; the match tests whether the
|
||||
actual warning category of the message is a subclass of the specified warning
|
||||
category. The full class name must be given. The *module* field matches the
|
||||
(fully-qualified) module name; this match is case-sensitive. The *line*
|
||||
field matches the line number, where zero matches all line numbers and is
|
||||
thus equivalent to an omitted line number.
|
||||
|
||||
.. seealso::
|
||||
:mod:`warnings` -- the warnings module
|
||||
|
||||
:pep:`230` -- Warning framework
|
||||
|
||||
:envvar:`PYTHONWARNINGS`
|
||||
|
||||
|
||||
.. cmdoption:: -x
|
||||
|
||||
Skip the first line of the source, allowing use of non-Unix forms of
|
||||
``#!cmd``. This is intended for a DOS specific hack only.
|
||||
|
||||
|
||||
.. cmdoption:: -X
|
||||
|
||||
Reserved for various implementation-specific options. CPython currently
|
||||
defines the following possible values:
|
||||
|
||||
* ``-X faulthandler`` to enable :mod:`faulthandler`;
|
||||
* ``-X showrefcount`` to output the total reference count and number of used
|
||||
memory blocks when the program finishes or after each statement in the
|
||||
interactive interpreter. This only works on debug builds.
|
||||
* ``-X tracemalloc`` to start tracing Python memory allocations using the
|
||||
:mod:`tracemalloc` module. By default, only the most recent frame is
|
||||
stored in a traceback of a trace. Use ``-X tracemalloc=NFRAME`` to start
|
||||
tracing with a traceback limit of *NFRAME* frames. See the
|
||||
:func:`tracemalloc.start` for more information.
|
||||
* ``-X showalloccount`` to output the total count of allocated objects for
|
||||
each type when the program finishes. This only works when Python was built with
|
||||
``COUNT_ALLOCS`` defined.
|
||||
|
||||
It also allows passing arbitrary values and retrieving them through the
|
||||
:data:`sys._xoptions` dictionary.
|
||||
|
||||
.. versionchanged:: 3.2
|
||||
The :option:`-X` option was added.
|
||||
|
||||
.. versionadded:: 3.3
|
||||
The ``-X faulthandler`` option.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
The ``-X showrefcount`` and ``-X tracemalloc`` options.
|
||||
|
||||
.. versionadded:: 3.6
|
||||
The ``-X showalloccount`` option.
|
||||
|
||||
|
||||
Options you shouldn't use
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. cmdoption:: -J
|
||||
|
||||
Reserved for use by Jython_.
|
||||
|
||||
.. _Jython: http://www.jython.org/
|
||||
|
||||
|
||||
.. _using-on-envvars:
|
||||
|
||||
Environment variables
|
||||
---------------------
|
||||
|
||||
These environment variables influence Python's behavior, they are processed
|
||||
before the command-line switches other than -E or -I. It is customary that
|
||||
command-line switches override environmental variables where there is a
|
||||
conflict.
|
||||
|
||||
.. envvar:: PYTHONHOME
|
||||
|
||||
Change the location of the standard Python libraries. By default, the
|
||||
libraries are searched in :file:`{prefix}/lib/python{version}` and
|
||||
:file:`{exec_prefix}/lib/python{version}`, where :file:`{prefix}` and
|
||||
:file:`{exec_prefix}` are installation-dependent directories, both defaulting
|
||||
to :file:`/usr/local`.
|
||||
|
||||
When :envvar:`PYTHONHOME` is set to a single directory, its value replaces
|
||||
both :file:`{prefix}` and :file:`{exec_prefix}`. To specify different values
|
||||
for these, set :envvar:`PYTHONHOME` to :file:`{prefix}:{exec_prefix}`.
|
||||
|
||||
|
||||
.. envvar:: PYTHONPATH
|
||||
|
||||
Augment the default search path for module files. The format is the same as
|
||||
the shell's :envvar:`PATH`: one or more directory pathnames separated by
|
||||
:data:`os.pathsep` (e.g. colons on Unix or semicolons on Windows).
|
||||
Non-existent directories are silently ignored.
|
||||
|
||||
In addition to normal directories, individual :envvar:`PYTHONPATH` entries
|
||||
may refer to zipfiles containing pure Python modules (in either source or
|
||||
compiled form). Extension modules cannot be imported from zipfiles.
|
||||
|
||||
The default search path is installation dependent, but generally begins with
|
||||
:file:`{prefix}/lib/python{version}` (see :envvar:`PYTHONHOME` above). It
|
||||
is *always* appended to :envvar:`PYTHONPATH`.
|
||||
|
||||
An additional directory will be inserted in the search path in front of
|
||||
:envvar:`PYTHONPATH` as described above under
|
||||
:ref:`using-on-interface-options`. The search path can be manipulated from
|
||||
within a Python program as the variable :data:`sys.path`.
|
||||
|
||||
|
||||
.. envvar:: PYTHONSTARTUP
|
||||
|
||||
If this is the name of a readable file, the Python commands in that file are
|
||||
executed before the first prompt is displayed in interactive mode. The file
|
||||
is executed in the same namespace where interactive commands are executed so
|
||||
that objects defined or imported in it can be used without qualification in
|
||||
the interactive session. You can also change the prompts :data:`sys.ps1` and
|
||||
:data:`sys.ps2` and the hook :data:`sys.__interactivehook__` in this file.
|
||||
|
||||
|
||||
.. envvar:: PYTHONOPTIMIZE
|
||||
|
||||
If this is set to a non-empty string it is equivalent to specifying the
|
||||
:option:`-O` option. If set to an integer, it is equivalent to specifying
|
||||
:option:`-O` multiple times.
|
||||
|
||||
|
||||
.. envvar:: PYTHONDEBUG
|
||||
|
||||
If this is set to a non-empty string it is equivalent to specifying the
|
||||
:option:`-d` option. If set to an integer, it is equivalent to specifying
|
||||
:option:`-d` multiple times.
|
||||
|
||||
|
||||
.. envvar:: PYTHONINSPECT
|
||||
|
||||
If this is set to a non-empty string it is equivalent to specifying the
|
||||
:option:`-i` option.
|
||||
|
||||
This variable can also be modified by Python code using :data:`os.environ`
|
||||
to force inspect mode on program termination.
|
||||
|
||||
|
||||
.. envvar:: PYTHONUNBUFFERED
|
||||
|
||||
If this is set to a non-empty string it is equivalent to specifying the
|
||||
:option:`-u` option.
|
||||
|
||||
|
||||
.. envvar:: PYTHONVERBOSE
|
||||
|
||||
If this is set to a non-empty string it is equivalent to specifying the
|
||||
:option:`-v` option. If set to an integer, it is equivalent to specifying
|
||||
:option:`-v` multiple times.
|
||||
|
||||
|
||||
.. envvar:: PYTHONCASEOK
|
||||
|
||||
If this is set, Python ignores case in :keyword:`import` statements. This
|
||||
only works on Windows and OS X.
|
||||
|
||||
|
||||
.. envvar:: PYTHONDONTWRITEBYTECODE
|
||||
|
||||
If this is set to a non-empty string, Python won't try to write ``.pyc``
|
||||
files on the import of source modules. This is equivalent to
|
||||
specifying the :option:`-B` option.
|
||||
|
||||
|
||||
.. envvar:: PYTHONHASHSEED
|
||||
|
||||
If this variable is not set or set to ``random``, a random value is used
|
||||
to seed the hashes of str, bytes and datetime objects.
|
||||
|
||||
If :envvar:`PYTHONHASHSEED` is set to an integer value, it is used as a fixed
|
||||
seed for generating the hash() of the types covered by the hash
|
||||
randomization.
|
||||
|
||||
Its purpose is to allow repeatable hashing, such as for selftests for the
|
||||
interpreter itself, or to allow a cluster of python processes to share hash
|
||||
values.
|
||||
|
||||
The integer must be a decimal number in the range [0,4294967295]. Specifying
|
||||
the value 0 will disable hash randomization.
|
||||
|
||||
.. versionadded:: 3.2.3
|
||||
|
||||
|
||||
.. envvar:: PYTHONIOENCODING
|
||||
|
||||
If this is set before running the interpreter, it overrides the encoding used
|
||||
for stdin/stdout/stderr, in the syntax ``encodingname:errorhandler``. Both
|
||||
the ``encodingname`` and the ``:errorhandler`` parts are optional and have
|
||||
the same meaning as in :func:`str.encode`.
|
||||
|
||||
For stderr, the ``:errorhandler`` part is ignored; the handler will always be
|
||||
``'backslashreplace'``.
|
||||
|
||||
.. versionchanged:: 3.4
|
||||
The ``encodingname`` part is now optional.
|
||||
|
||||
.. versionchanged:: 3.6
|
||||
On Windows, the encoding specified by this variable is ignored for interactive
|
||||
console buffers unless :envvar:`PYTHONLEGACYWINDOWSSTDIO` is also specified.
|
||||
Files and pipes redirected through the standard streams are not affected.
|
||||
|
||||
.. envvar:: PYTHONNOUSERSITE
|
||||
|
||||
If this is set, Python won't add the :data:`user site-packages directory
|
||||
<site.USER_SITE>` to :data:`sys.path`.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:pep:`370` -- Per user site-packages directory
|
||||
|
||||
|
||||
.. envvar:: PYTHONUSERBASE
|
||||
|
||||
Defines the :data:`user base directory <site.USER_BASE>`, which is used to
|
||||
compute the path of the :data:`user site-packages directory <site.USER_SITE>`
|
||||
and :ref:`Distutils installation paths <inst-alt-install-user>` for
|
||||
``python setup.py install --user``.
|
||||
|
||||
.. seealso::
|
||||
|
||||
:pep:`370` -- Per user site-packages directory
|
||||
|
||||
|
||||
.. envvar:: PYTHONEXECUTABLE
|
||||
|
||||
If this environment variable is set, ``sys.argv[0]`` will be set to its
|
||||
value instead of the value got through the C runtime. Only works on
|
||||
Mac OS X.
|
||||
|
||||
.. envvar:: PYTHONWARNINGS
|
||||
|
||||
This is equivalent to the :option:`-W` option. If set to a comma
|
||||
separated string, it is equivalent to specifying :option:`-W` multiple
|
||||
times.
|
||||
|
||||
.. envvar:: PYTHONFAULTHANDLER
|
||||
|
||||
If this environment variable is set to a non-empty string,
|
||||
:func:`faulthandler.enable` is called at startup: install a handler for
|
||||
:const:`SIGSEGV`, :const:`SIGFPE`, :const:`SIGABRT`, :const:`SIGBUS` and
|
||||
:const:`SIGILL` signals to dump the Python traceback. This is equivalent to
|
||||
:option:`-X` ``faulthandler`` option.
|
||||
|
||||
.. versionadded:: 3.3
|
||||
|
||||
|
||||
.. envvar:: PYTHONTRACEMALLOC
|
||||
|
||||
If this environment variable is set to a non-empty string, start tracing
|
||||
Python memory allocations using the :mod:`tracemalloc` module. The value of
|
||||
the variable is the maximum number of frames stored in a traceback of a
|
||||
trace. For example, ``PYTHONTRACEMALLOC=1`` stores only the most recent
|
||||
frame. See the :func:`tracemalloc.start` for more information.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
.. envvar:: PYTHONASYNCIODEBUG
|
||||
|
||||
If this environment variable is set to a non-empty string, enable the
|
||||
:ref:`debug mode <asyncio-debug-mode>` of the :mod:`asyncio` module.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
|
||||
|
||||
.. envvar:: PYTHONMALLOC
|
||||
|
||||
Set the Python memory allocators and/or install debug hooks.
|
||||
|
||||
Set the family of memory allocators used by Python:
|
||||
|
||||
* ``malloc``: use the :c:func:`malloc` function of the C library
|
||||
for all domains (:c:data:`PYMEM_DOMAIN_RAW`, :c:data:`PYMEM_DOMAIN_MEM`,
|
||||
:c:data:`PYMEM_DOMAIN_OBJ`).
|
||||
* ``pymalloc``: use the :ref:`pymalloc allocator <pymalloc>` for
|
||||
:c:data:`PYMEM_DOMAIN_MEM` and :c:data:`PYMEM_DOMAIN_OBJ` domains and use
|
||||
the :c:func:`malloc` function for the :c:data:`PYMEM_DOMAIN_RAW` domain.
|
||||
|
||||
Install debug hooks:
|
||||
|
||||
* ``debug``: install debug hooks on top of the default memory allocator
|
||||
* ``malloc_debug``: same as ``malloc`` but also install debug hooks
|
||||
* ``pymalloc_debug``: same as ``pymalloc`` but also install debug hooks
|
||||
|
||||
When Python is compiled in release mode, the default is ``pymalloc``. When
|
||||
compiled in debug mode, the default is ``pymalloc_debug`` and the debug hooks
|
||||
are used automatically.
|
||||
|
||||
If Python is configured without ``pymalloc`` support, ``pymalloc`` and
|
||||
``pymalloc_debug`` are not available, the default is ``malloc`` in release
|
||||
mode and ``malloc_debug`` in debug mode.
|
||||
|
||||
See the :c:func:`PyMem_SetupDebugHooks` function for debug hooks on Python
|
||||
memory allocators.
|
||||
|
||||
.. versionadded:: 3.6
|
||||
|
||||
|
||||
.. envvar:: PYTHONMALLOCSTATS
|
||||
|
||||
If set to a non-empty string, Python will print statistics of the
|
||||
:ref:`pymalloc memory allocator <pymalloc>` every time a new pymalloc object
|
||||
arena is created, and on shutdown.
|
||||
|
||||
This variable is ignored if the :envvar:`PYTHONMALLOC` environment variable
|
||||
is used to force the :c:func:`malloc` allocator of the C library, or if
|
||||
Python is configured without ``pymalloc`` support.
|
||||
|
||||
.. versionchanged:: 3.6
|
||||
This variable can now also be used on Python compiled in release mode.
|
||||
It now has no effect if set to an empty string.
|
||||
|
||||
|
||||
.. envvar:: PYTHONLEGACYWINDOWSFSENCODING
|
||||
|
||||
If set to a non-empty string, the default filesystem encoding and errors mode
|
||||
will revert to their pre-3.6 values of 'mbcs' and 'replace', respectively.
|
||||
Otherwise, the new defaults 'utf-8' and 'surrogatepass' are used.
|
||||
|
||||
This may also be enabled at runtime with
|
||||
:func:`sys._enablelegacywindowsfsencoding()`.
|
||||
|
||||
Availability: Windows
|
||||
|
||||
.. versionadded:: 3.6
|
||||
See :pep:`529` for more details.
|
||||
|
||||
.. envvar:: PYTHONLEGACYWINDOWSSTDIO
|
||||
|
||||
If set to a non-empty string, does not use the new console reader and
|
||||
writer. This means that Unicode characters will be encoded according to
|
||||
the active console code page, rather than using utf-8.
|
||||
|
||||
This variable is ignored if the standard streams are redirected (to files
|
||||
or pipes) rather than referring to console buffers.
|
||||
|
||||
Availability: Windows
|
||||
|
||||
.. versionadded:: 3.6
|
||||
|
||||
Debug-mode variables
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Setting these variables only has an effect in a debug build of Python, that is,
|
||||
if Python was configured with the ``--with-pydebug`` build option.
|
||||
|
||||
.. envvar:: PYTHONTHREADDEBUG
|
||||
|
||||
If set, Python will print threading debug info.
|
||||
|
||||
|
||||
.. envvar:: PYTHONDUMPREFS
|
||||
|
||||
If set, Python will dump objects and reference counts still alive after
|
||||
shutting down the interpreter.
|
19
third_party/python/Doc/using/index.rst
vendored
Normal file
19
third_party/python/Doc/using/index.rst
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
.. _using-index:
|
||||
|
||||
##########################
|
||||
Python Setup and Usage
|
||||
##########################
|
||||
|
||||
|
||||
This part of the documentation is devoted to general information on the setup
|
||||
of the Python environment on different platforms, the invocation of the
|
||||
interpreter and things that make working with Python easier.
|
||||
|
||||
|
||||
.. toctree::
|
||||
:numbered:
|
||||
|
||||
cmdline.rst
|
||||
unix.rst
|
||||
windows.rst
|
||||
mac.rst
|
183
third_party/python/Doc/using/mac.rst
vendored
Normal file
183
third_party/python/Doc/using/mac.rst
vendored
Normal file
|
@ -0,0 +1,183 @@
|
|||
|
||||
.. _using-on-mac:
|
||||
|
||||
***************************
|
||||
Using Python on a Macintosh
|
||||
***************************
|
||||
|
||||
:Author: Bob Savage <bobsavage@mac.com>
|
||||
|
||||
|
||||
Python on a Macintosh running Mac OS X is in principle very similar to Python on
|
||||
any other Unix platform, but there are a number of additional features such as
|
||||
the IDE and the Package Manager that are worth pointing out.
|
||||
|
||||
.. _getting-osx:
|
||||
|
||||
Getting and Installing MacPython
|
||||
================================
|
||||
|
||||
Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple. If you wish, you
|
||||
are invited to install the most recent version of Python 3 from the Python
|
||||
website (https://www.python.org). A current "universal binary" build of Python,
|
||||
which runs natively on the Mac's new Intel and legacy PPC CPU's, is available
|
||||
there.
|
||||
|
||||
What you get after installing is a number of things:
|
||||
|
||||
* A :file:`MacPython 3.6` folder in your :file:`Applications` folder. In here
|
||||
you find IDLE, the development environment that is a standard part of official
|
||||
Python distributions; PythonLauncher, which handles double-clicking Python
|
||||
scripts from the Finder; and the "Build Applet" tool, which allows you to
|
||||
package Python scripts as standalone applications on your system.
|
||||
|
||||
* A framework :file:`/Library/Frameworks/Python.framework`, which includes the
|
||||
Python executable and libraries. The installer adds this location to your shell
|
||||
path. To uninstall MacPython, you can simply remove these three things. A
|
||||
symlink to the Python executable is placed in /usr/local/bin/.
|
||||
|
||||
The Apple-provided build of Python is installed in
|
||||
:file:`/System/Library/Frameworks/Python.framework` and :file:`/usr/bin/python`,
|
||||
respectively. You should never modify or delete these, as they are
|
||||
Apple-controlled and are used by Apple- or third-party software. Remember that
|
||||
if you choose to install a newer Python version from python.org, you will have
|
||||
two different but functional Python installations on your computer, so it will
|
||||
be important that your paths and usages are consistent with what you want to do.
|
||||
|
||||
IDLE includes a help menu that allows you to access Python documentation. If you
|
||||
are completely new to Python you should start reading the tutorial introduction
|
||||
in that document.
|
||||
|
||||
If you are familiar with Python on other Unix platforms you should read the
|
||||
section on running Python scripts from the Unix shell.
|
||||
|
||||
|
||||
How to run a Python script
|
||||
--------------------------
|
||||
|
||||
Your best way to get started with Python on Mac OS X is through the IDLE
|
||||
integrated development environment, see section :ref:`ide` and use the Help menu
|
||||
when the IDE is running.
|
||||
|
||||
If you want to run Python scripts from the Terminal window command line or from
|
||||
the Finder you first need an editor to create your script. Mac OS X comes with a
|
||||
number of standard Unix command line editors, :program:`vim` and
|
||||
:program:`emacs` among them. If you want a more Mac-like editor,
|
||||
:program:`BBEdit` or :program:`TextWrangler` from Bare Bones Software (see
|
||||
http://www.barebones.com/products/bbedit/index.html) are good choices, as is
|
||||
:program:`TextMate` (see https://macromates.com/). Other editors include
|
||||
:program:`Gvim` (http://macvim.org) and :program:`Aquamacs`
|
||||
(http://aquamacs.org/).
|
||||
|
||||
To run your script from the Terminal window you must make sure that
|
||||
:file:`/usr/local/bin` is in your shell search path.
|
||||
|
||||
To run your script from the Finder you have two options:
|
||||
|
||||
* Drag it to :program:`PythonLauncher`
|
||||
|
||||
* Select :program:`PythonLauncher` as the default application to open your
|
||||
script (or any .py script) through the finder Info window and double-click it.
|
||||
:program:`PythonLauncher` has various preferences to control how your script is
|
||||
launched. Option-dragging allows you to change these for one invocation, or use
|
||||
its Preferences menu to change things globally.
|
||||
|
||||
|
||||
.. _osx-gui-scripts:
|
||||
|
||||
Running scripts with a GUI
|
||||
--------------------------
|
||||
|
||||
With older versions of Python, there is one Mac OS X quirk that you need to be
|
||||
aware of: programs that talk to the Aqua window manager (in other words,
|
||||
anything that has a GUI) need to be run in a special way. Use :program:`pythonw`
|
||||
instead of :program:`python` to start such scripts.
|
||||
|
||||
With Python 3.6, you can use either :program:`python` or :program:`pythonw`.
|
||||
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
Python on OS X honors all standard Unix environment variables such as
|
||||
:envvar:`PYTHONPATH`, but setting these variables for programs started from the
|
||||
Finder is non-standard as the Finder does not read your :file:`.profile` or
|
||||
:file:`.cshrc` at startup. You need to create a file
|
||||
:file:`~/.MacOSX/environment.plist`. See Apple's Technical Document QA1067 for
|
||||
details.
|
||||
|
||||
For more information on installation Python packages in MacPython, see section
|
||||
:ref:`mac-package-manager`.
|
||||
|
||||
|
||||
.. _ide:
|
||||
|
||||
The IDE
|
||||
=======
|
||||
|
||||
MacPython ships with the standard IDLE development environment. A good
|
||||
introduction to using IDLE can be found at
|
||||
https://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html.
|
||||
|
||||
|
||||
.. _mac-package-manager:
|
||||
|
||||
Installing Additional Python Packages
|
||||
=====================================
|
||||
|
||||
There are several methods to install additional Python packages:
|
||||
|
||||
* Packages can be installed via the standard Python distutils mode (``python
|
||||
setup.py install``).
|
||||
|
||||
* Many packages can also be installed via the :program:`setuptools` extension
|
||||
or :program:`pip` wrapper, see https://pip.pypa.io/.
|
||||
|
||||
|
||||
GUI Programming on the Mac
|
||||
==========================
|
||||
|
||||
There are several options for building GUI applications on the Mac with Python.
|
||||
|
||||
*PyObjC* is a Python binding to Apple's Objective-C/Cocoa framework, which is
|
||||
the foundation of most modern Mac development. Information on PyObjC is
|
||||
available from https://pythonhosted.org/pyobjc/.
|
||||
|
||||
The standard Python GUI toolkit is :mod:`tkinter`, based on the cross-platform
|
||||
Tk toolkit (https://www.tcl.tk). An Aqua-native version of Tk is bundled with OS
|
||||
X by Apple, and the latest version can be downloaded and installed from
|
||||
https://www.activestate.com; it can also be built from source.
|
||||
|
||||
*wxPython* is another popular cross-platform GUI toolkit that runs natively on
|
||||
Mac OS X. Packages and documentation are available from http://www.wxpython.org.
|
||||
|
||||
*PyQt* is another popular cross-platform GUI toolkit that runs natively on Mac
|
||||
OS X. More information can be found at
|
||||
https://riverbankcomputing.com/software/pyqt/intro.
|
||||
|
||||
|
||||
Distributing Python Applications on the Mac
|
||||
===========================================
|
||||
|
||||
The "Build Applet" tool that is placed in the MacPython 3.6 folder is fine for
|
||||
packaging small Python scripts on your own machine to run as a standard Mac
|
||||
application. This tool, however, is not robust enough to distribute Python
|
||||
applications to other users.
|
||||
|
||||
The standard tool for deploying standalone Python applications on the Mac is
|
||||
:program:`py2app`. More information on installing and using py2app can be found
|
||||
at http://undefined.org/python/#py2app.
|
||||
|
||||
|
||||
Other Resources
|
||||
===============
|
||||
|
||||
The MacPython mailing list is an excellent support resource for Python users and
|
||||
developers on the Mac:
|
||||
|
||||
https://www.python.org/community/sigs/current/pythonmac-sig/
|
||||
|
||||
Another useful resource is the MacPython wiki:
|
||||
|
||||
https://wiki.python.org/moin/MacPython
|
||||
|
147
third_party/python/Doc/using/unix.rst
vendored
Normal file
147
third_party/python/Doc/using/unix.rst
vendored
Normal file
|
@ -0,0 +1,147 @@
|
|||
.. highlightlang:: sh
|
||||
|
||||
.. _using-on-unix:
|
||||
|
||||
********************************
|
||||
Using Python on Unix platforms
|
||||
********************************
|
||||
|
||||
.. sectionauthor:: Shriphani Palakodety
|
||||
|
||||
|
||||
Getting and installing the latest version of Python
|
||||
===================================================
|
||||
|
||||
On Linux
|
||||
--------
|
||||
|
||||
Python comes preinstalled on most Linux distributions, and is available as a
|
||||
package on all others. However there are certain features you might want to use
|
||||
that are not available on your distro's package. You can easily compile the
|
||||
latest version of Python from source.
|
||||
|
||||
In the event that Python doesn't come preinstalled and isn't in the repositories as
|
||||
well, you can easily make packages for your own distro. Have a look at the
|
||||
following links:
|
||||
|
||||
.. seealso::
|
||||
|
||||
https://www.debian.org/doc/manuals/maint-guide/first.en.html
|
||||
for Debian users
|
||||
https://en.opensuse.org/Portal:Packaging
|
||||
for OpenSuse users
|
||||
https://docs.fedoraproject.org/en-US/Fedora_Draft_Documentation/0.1/html/RPM_Guide/ch-creating-rpms.html
|
||||
for Fedora users
|
||||
http://www.slackbook.org/html/package-management-making-packages.html
|
||||
for Slackware users
|
||||
|
||||
|
||||
On FreeBSD and OpenBSD
|
||||
----------------------
|
||||
|
||||
* FreeBSD users, to add the package use::
|
||||
|
||||
pkg install python3
|
||||
|
||||
* OpenBSD users, to add the package use::
|
||||
|
||||
pkg_add -r python
|
||||
|
||||
pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/<insert your architecture here>/python-<version>.tgz
|
||||
|
||||
For example i386 users get the 2.5.1 version of Python using::
|
||||
|
||||
pkg_add ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz
|
||||
|
||||
|
||||
On OpenSolaris
|
||||
--------------
|
||||
|
||||
You can get Python from `OpenCSW <https://www.opencsw.org/>`_. Various versions
|
||||
of Python are available and can be installed with e.g. ``pkgutil -i python27``.
|
||||
|
||||
|
||||
.. _building-python-on-unix:
|
||||
|
||||
Building Python
|
||||
===============
|
||||
|
||||
If you want to compile CPython yourself, first thing you should do is get the
|
||||
`source <https://www.python.org/downloads/source/>`_. You can download either the
|
||||
latest release's source or just grab a fresh `clone
|
||||
<https://devguide.python.org/setup/#getting-the-source-code>`_. (If you want
|
||||
to contribute patches, you will need a clone.)
|
||||
|
||||
The build process consists in the usual ::
|
||||
|
||||
./configure
|
||||
make
|
||||
make install
|
||||
|
||||
invocations. Configuration options and caveats for specific Unix platforms are
|
||||
extensively documented in the :source:`README.rst` file in the root of the Python
|
||||
source tree.
|
||||
|
||||
.. warning::
|
||||
|
||||
``make install`` can overwrite or masquerade the :file:`python3` binary.
|
||||
``make altinstall`` is therefore recommended instead of ``make install``
|
||||
since it only installs :file:`{exec_prefix}/bin/python{version}`.
|
||||
|
||||
|
||||
Python-related paths and files
|
||||
==============================
|
||||
|
||||
These are subject to difference depending on local installation conventions;
|
||||
:envvar:`prefix` (``${prefix}``) and :envvar:`exec_prefix` (``${exec_prefix}``)
|
||||
are installation-dependent and should be interpreted as for GNU software; they
|
||||
may be the same.
|
||||
|
||||
For example, on most Linux systems, the default for both is :file:`/usr`.
|
||||
|
||||
+-----------------------------------------------+------------------------------------------+
|
||||
| File/directory | Meaning |
|
||||
+===============================================+==========================================+
|
||||
| :file:`{exec_prefix}/bin/python3` | Recommended location of the interpreter. |
|
||||
+-----------------------------------------------+------------------------------------------+
|
||||
| :file:`{prefix}/lib/python{version}`, | Recommended locations of the directories |
|
||||
| :file:`{exec_prefix}/lib/python{version}` | containing the standard modules. |
|
||||
+-----------------------------------------------+------------------------------------------+
|
||||
| :file:`{prefix}/include/python{version}`, | Recommended locations of the directories |
|
||||
| :file:`{exec_prefix}/include/python{version}` | containing the include files needed for |
|
||||
| | developing Python extensions and |
|
||||
| | embedding the interpreter. |
|
||||
+-----------------------------------------------+------------------------------------------+
|
||||
|
||||
|
||||
Miscellaneous
|
||||
=============
|
||||
|
||||
To easily use Python scripts on Unix, you need to make them executable,
|
||||
e.g. with
|
||||
|
||||
.. code-block:: shell-session
|
||||
|
||||
$ chmod +x script
|
||||
|
||||
and put an appropriate Shebang line at the top of the script. A good choice is
|
||||
usually ::
|
||||
|
||||
#!/usr/bin/env python3
|
||||
|
||||
which searches for the Python interpreter in the whole :envvar:`PATH`. However,
|
||||
some Unices may not have the :program:`env` command, so you may need to hardcode
|
||||
``/usr/bin/python3`` as the interpreter path.
|
||||
|
||||
To use shell commands in your Python scripts, look at the :mod:`subprocess` module.
|
||||
|
||||
|
||||
Editors and IDEs
|
||||
================
|
||||
|
||||
There are a number of IDEs that support Python programming language.
|
||||
Many editors and IDEs provide syntax highlighting, debugging tools, and :pep:`8` checks.
|
||||
|
||||
Please go to `Python Editors <https://wiki.python.org/moin/PythonEditors>`_ and
|
||||
`Integrated Development Environments <https://wiki.python.org/moin/IntegratedDevelopmentEnvironments>`_
|
||||
for a comprehensive list.
|
122
third_party/python/Doc/using/venv-create.inc
vendored
Normal file
122
third_party/python/Doc/using/venv-create.inc
vendored
Normal file
|
@ -0,0 +1,122 @@
|
|||
Creation of :ref:`virtual environments <venv-def>` is done by executing the
|
||||
command ``venv``::
|
||||
|
||||
python3 -m venv /path/to/new/virtual/environment
|
||||
|
||||
Running this command creates the target directory (creating any parent
|
||||
directories that don't exist already) and places a ``pyvenv.cfg`` file in it
|
||||
with a ``home`` key pointing to the Python installation from which the command
|
||||
was run. It also creates a ``bin`` (or ``Scripts`` on Windows) subdirectory
|
||||
containing a copy/symlink of the Python binary/binaries (as appropriate for the
|
||||
platform or arguments used at environment creation time). It also creates an
|
||||
(initially empty) ``lib/pythonX.Y/site-packages`` subdirectory
|
||||
(on Windows, this is ``Lib\site-packages``). If an existing
|
||||
directory is specified, it will be re-used.
|
||||
|
||||
.. deprecated:: 3.6
|
||||
``pyvenv`` was the recommended tool for creating virtual environments for
|
||||
Python 3.3 and 3.4, and is `deprecated in Python 3.6
|
||||
<https://docs.python.org/dev/whatsnew/3.6.html#deprecated-features>`_.
|
||||
|
||||
.. versionchanged:: 3.5
|
||||
The use of ``venv`` is now recommended for creating virtual environments.
|
||||
|
||||
.. seealso::
|
||||
|
||||
`Python Packaging User Guide: Creating and using virtual environments
|
||||
<https://packaging.python.org/installing/#creating-virtual-environments>`__
|
||||
|
||||
.. highlight:: none
|
||||
|
||||
On Windows, invoke the ``venv`` command as follows::
|
||||
|
||||
c:\>c:\Python35\python -m venv c:\path\to\myenv
|
||||
|
||||
Alternatively, if you configured the ``PATH`` and ``PATHEXT`` variables for
|
||||
your :ref:`Python installation <using-on-windows>`::
|
||||
|
||||
c:\>python -m venv c:\path\to\myenv
|
||||
|
||||
The command, if run with ``-h``, will show the available options::
|
||||
|
||||
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
|
||||
[--upgrade] [--without-pip]
|
||||
ENV_DIR [ENV_DIR ...]
|
||||
|
||||
Creates virtual Python environments in one or more target directories.
|
||||
|
||||
positional arguments:
|
||||
ENV_DIR A directory to create the environment in.
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
--system-site-packages
|
||||
Give the virtual environment access to the system
|
||||
site-packages dir.
|
||||
--symlinks Try to use symlinks rather than copies, when symlinks
|
||||
are not the default for the platform.
|
||||
--copies Try to use copies rather than symlinks, even when
|
||||
symlinks are the default for the platform.
|
||||
--clear Delete the contents of the environment directory if it
|
||||
already exists, before environment creation.
|
||||
--upgrade Upgrade the environment directory to use this version
|
||||
of Python, assuming Python has been upgraded in-place.
|
||||
--without-pip Skips installing or upgrading pip in the virtual
|
||||
environment (pip is bootstrapped by default)
|
||||
|
||||
Once an environment has been created, you may wish to activate it, e.g. by
|
||||
sourcing an activate script in its bin directory.
|
||||
|
||||
.. versionchanged:: 3.4
|
||||
Installs pip by default, added the ``--without-pip`` and ``--copies``
|
||||
options
|
||||
|
||||
.. versionchanged:: 3.4
|
||||
In earlier versions, if the target directory already existed, an error was
|
||||
raised, unless the ``--clear`` or ``--upgrade`` option was provided.
|
||||
|
||||
The created ``pyvenv.cfg`` file also includes the
|
||||
``include-system-site-packages`` key, set to ``true`` if ``venv`` is
|
||||
run with the ``--system-site-packages`` option, ``false`` otherwise.
|
||||
|
||||
Unless the ``--without-pip`` option is given, :mod:`ensurepip` will be
|
||||
invoked to bootstrap ``pip`` into the virtual environment.
|
||||
|
||||
Multiple paths can be given to ``venv``, in which case an identical virtual
|
||||
environment will be created, according to the given options, at each provided
|
||||
path.
|
||||
|
||||
Once a virtual environment has been created, it can be "activated" using a
|
||||
script in the virtual environment's binary directory. The invocation of the
|
||||
script is platform-specific (`<venv>` must be replaced by the path of the
|
||||
directory containing the virtual environment):
|
||||
|
||||
+-------------+-----------------+-----------------------------------------+
|
||||
| Platform | Shell | Command to activate virtual environment |
|
||||
+=============+=================+=========================================+
|
||||
| Posix | bash/zsh | $ source <venv>/bin/activate |
|
||||
+-------------+-----------------+-----------------------------------------+
|
||||
| | fish | $ . <venv>/bin/activate.fish |
|
||||
+-------------+-----------------+-----------------------------------------+
|
||||
| | csh/tcsh | $ source <venv>/bin/activate.csh |
|
||||
+-------------+-----------------+-----------------------------------------+
|
||||
| Windows | cmd.exe | C:\\> <venv>\\Scripts\\activate.bat |
|
||||
+-------------+-----------------+-----------------------------------------+
|
||||
| | PowerShell | PS C:\\> <venv>\\Scripts\\Activate.ps1 |
|
||||
+-------------+-----------------+-----------------------------------------+
|
||||
|
||||
You don't specifically *need* to activate an environment; activation just
|
||||
prepends the virtual environment's binary directory to your path, so that
|
||||
"python" invokes the virtual environment's Python interpreter and you can run
|
||||
installed scripts without having to use their full path. However, all scripts
|
||||
installed in a virtual environment should be runnable without activating it,
|
||||
and run with the virtual environment's Python automatically.
|
||||
|
||||
You can deactivate a virtual environment by typing "deactivate" in your shell.
|
||||
The exact mechanism is platform-specific: for example, the Bash activation
|
||||
script defines a "deactivate" function, whereas on Windows there are separate
|
||||
scripts called ``deactivate.bat`` and ``Deactivate.ps1`` which are installed
|
||||
when the virtual environment is created.
|
||||
|
||||
.. versionadded:: 3.4
|
||||
``fish`` and ``csh`` activation scripts.
|
BIN
third_party/python/Doc/using/win_installer.png
vendored
Normal file
BIN
third_party/python/Doc/using/win_installer.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
1016
third_party/python/Doc/using/windows.rst
vendored
Normal file
1016
third_party/python/Doc/using/windows.rst
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue