780 lines
75 KiB
HTML
780 lines
75 KiB
HTML
|
|
|||
|
<!DOCTYPE html>
|
|||
|
|
|||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|||
|
<head>
|
|||
|
<meta charset="utf-8" />
|
|||
|
<title>venv — Creation of virtual environments — Python 3.7.4 documentation</title>
|
|||
|
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
|
|||
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|||
|
|
|||
|
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/language_data.js"></script>
|
|||
|
|
|||
|
<script type="text/javascript" src="../_static/sidebar.js"></script>
|
|||
|
|
|||
|
<link rel="search" type="application/opensearchdescription+xml"
|
|||
|
title="Search within Python 3.7.4 documentation"
|
|||
|
href="../_static/opensearch.xml"/>
|
|||
|
<link rel="author" title="About these documents" href="../about.html" />
|
|||
|
<link rel="index" title="Index" href="../genindex.html" />
|
|||
|
<link rel="search" title="Search" href="../search.html" />
|
|||
|
<link rel="copyright" title="Copyright" href="../copyright.html" />
|
|||
|
<link rel="next" title="zipapp — Manage executable Python zip archives" href="zipapp.html" />
|
|||
|
<link rel="prev" title="ensurepip — Bootstrapping the pip installer" href="ensurepip.html" />
|
|||
|
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
|
|||
|
<link rel="canonical" href="https://docs.python.org/3/library/venv.html" />
|
|||
|
|
|||
|
<script type="text/javascript" src="../_static/copybutton.js"></script>
|
|||
|
<script type="text/javascript" src="../_static/switchers.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<style>
|
|||
|
@media only screen {
|
|||
|
table.full-width-table {
|
|||
|
width: 100%;
|
|||
|
}
|
|||
|
}
|
|||
|
</style>
|
|||
|
|
|||
|
|
|||
|
</head><body>
|
|||
|
|
|||
|
<div class="related" role="navigation" aria-label="related navigation">
|
|||
|
<h3>Navigation</h3>
|
|||
|
<ul>
|
|||
|
<li class="right" style="margin-right: 10px">
|
|||
|
<a href="../genindex.html" title="General Index"
|
|||
|
accesskey="I">index</a></li>
|
|||
|
<li class="right" >
|
|||
|
<a href="../py-modindex.html" title="Python Module Index"
|
|||
|
>modules</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="zipapp.html" title="zipapp — Manage executable Python zip archives"
|
|||
|
accesskey="N">next</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="ensurepip.html" title="ensurepip — Bootstrapping the pip installer"
|
|||
|
accesskey="P">previous</a> |</li>
|
|||
|
<li><img src="../_static/py.png" alt=""
|
|||
|
style="vertical-align: middle; margin-top: -1px"/></li>
|
|||
|
<li><a href="https://www.python.org/">Python</a> »</li>
|
|||
|
<li>
|
|||
|
<span class="language_switcher_placeholder">en</span>
|
|||
|
<span class="version_switcher_placeholder">3.7.4</span>
|
|||
|
<a href="../index.html">Documentation </a> »
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
|||
|
<li class="nav-item nav-item-2"><a href="distribution.html" accesskey="U">Software Packaging and Distribution</a> »</li>
|
|||
|
<li class="right">
|
|||
|
|
|||
|
|
|||
|
<div class="inline-search" style="display: none" role="search">
|
|||
|
<form class="inline-search" action="../search.html" method="get">
|
|||
|
<input placeholder="Quick search" type="text" name="q" />
|
|||
|
<input type="submit" value="Go" />
|
|||
|
<input type="hidden" name="check_keywords" value="yes" />
|
|||
|
<input type="hidden" name="area" value="default" />
|
|||
|
</form>
|
|||
|
</div>
|
|||
|
<script type="text/javascript">$('.inline-search').show(0);</script>
|
|||
|
|
|
|||
|
</li>
|
|||
|
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="document">
|
|||
|
<div class="documentwrapper">
|
|||
|
<div class="bodywrapper">
|
|||
|
<div class="body" role="main">
|
|||
|
|
|||
|
<div class="section" id="module-venv">
|
|||
|
<span id="venv-creation-of-virtual-environments"></span><h1><a class="reference internal" href="#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> — Creation of virtual environments<a class="headerlink" href="#module-venv" title="Permalink to this headline">¶</a></h1>
|
|||
|
<div class="versionadded">
|
|||
|
<p><span class="versionmodified added">New in version 3.3.</span></p>
|
|||
|
</div>
|
|||
|
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/venv/">Lib/venv/</a></p>
|
|||
|
<hr class="docutils" id="index-0" />
|
|||
|
<p>The <a class="reference internal" href="#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code></a> module provides support for creating lightweight “virtual
|
|||
|
environments” with their own site directories, optionally isolated from system
|
|||
|
site directories. Each virtual environment has its own Python binary (which
|
|||
|
matches the version of the binary that was used to create this environment) and
|
|||
|
can have its own independent set of installed Python packages in its site
|
|||
|
directories.</p>
|
|||
|
<p>See <span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0405"><strong>PEP 405</strong></a> for more information about Python virtual environments.</p>
|
|||
|
<div class="admonition seealso">
|
|||
|
<p class="admonition-title">See also</p>
|
|||
|
<p><a class="reference external" href="https://packaging.python.org/installing/#creating-virtual-environments">Python Packaging User Guide: Creating and using virtual environments</a></p>
|
|||
|
</div>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>The <code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> script has been deprecated as of Python 3.6 in favor of using
|
|||
|
<code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">-m</span> <span class="pre">venv</span></code> to help prevent any potential confusion as to which
|
|||
|
Python interpreter a virtual environment will be based on.</p>
|
|||
|
</div>
|
|||
|
<div class="section" id="creating-virtual-environments">
|
|||
|
<h2>Creating virtual environments<a class="headerlink" href="#creating-virtual-environments" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>Creation of <a class="reference internal" href="#venv-def"><span class="std std-ref">virtual environments</span></a> is done by executing the
|
|||
|
command <code class="docutils literal notranslate"><span class="pre">venv</span></code>:</p>
|
|||
|
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python3</span> <span class="o">-</span><span class="n">m</span> <span class="n">venv</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">new</span><span class="o">/</span><span class="n">virtual</span><span class="o">/</span><span class="n">environment</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Running this command creates the target directory (creating any parent
|
|||
|
directories that don’t exist already) and places a <code class="docutils literal notranslate"><span class="pre">pyvenv.cfg</span></code> file in it
|
|||
|
with a <code class="docutils literal notranslate"><span class="pre">home</span></code> key pointing to the Python installation from which the command
|
|||
|
was run. It also creates a <code class="docutils literal notranslate"><span class="pre">bin</span></code> (or <code class="docutils literal notranslate"><span class="pre">Scripts</span></code> 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) <code class="docutils literal notranslate"><span class="pre">lib/pythonX.Y/site-packages</span></code> subdirectory
|
|||
|
(on Windows, this is <code class="docutils literal notranslate"><span class="pre">Lib\site-packages</span></code>). If an existing
|
|||
|
directory is specified, it will be re-used.</p>
|
|||
|
<div class="deprecated">
|
|||
|
<p><span class="versionmodified deprecated">Deprecated since version 3.6: </span><code class="docutils literal notranslate"><span class="pre">pyvenv</span></code> was the recommended tool for creating virtual environments for
|
|||
|
Python 3.3 and 3.4, and is <a class="reference external" href="https://docs.python.org/dev/whatsnew/3.6.html#deprecated-features">deprecated in Python 3.6</a>.</p>
|
|||
|
</div>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.5: </span>The use of <code class="docutils literal notranslate"><span class="pre">venv</span></code> is now recommended for creating virtual environments.</p>
|
|||
|
</div>
|
|||
|
<p>On Windows, invoke the <code class="docutils literal notranslate"><span class="pre">venv</span></code> command as follows:</p>
|
|||
|
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>c:\>c:\Python35\python -m venv c:\path\to\myenv
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Alternatively, if you configured the <code class="docutils literal notranslate"><span class="pre">PATH</span></code> and <code class="docutils literal notranslate"><span class="pre">PATHEXT</span></code> variables for
|
|||
|
your <a class="reference internal" href="../using/windows.html#using-on-windows"><span class="std std-ref">Python installation</span></a>:</p>
|
|||
|
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>c:\>python -m venv c:\path\to\myenv
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>The command, if run with <code class="docutils literal notranslate"><span class="pre">-h</span></code>, will show the available options:</p>
|
|||
|
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear]
|
|||
|
[--upgrade] [--without-pip] [--prompt PROMPT]
|
|||
|
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)
|
|||
|
--prompt PROMPT Provides an alternative prompt prefix for this
|
|||
|
environment.
|
|||
|
|
|||
|
Once an environment has been created, you may wish to activate it, e.g. by
|
|||
|
sourcing an activate script in its bin directory.
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.4: </span>Installs pip by default, added the <code class="docutils literal notranslate"><span class="pre">--without-pip</span></code> and <code class="docutils literal notranslate"><span class="pre">--copies</span></code>
|
|||
|
options</p>
|
|||
|
</div>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.4: </span>In earlier versions, if the target directory already existed, an error was
|
|||
|
raised, unless the <code class="docutils literal notranslate"><span class="pre">--clear</span></code> or <code class="docutils literal notranslate"><span class="pre">--upgrade</span></code> option was provided.</p>
|
|||
|
</div>
|
|||
|
<div class="admonition note">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>While symlinks are supported on Windows, they are not recommended. Of
|
|||
|
particular note is that double-clicking <code class="docutils literal notranslate"><span class="pre">python.exe</span></code> in File Explorer
|
|||
|
will resolve the symlink eagerly and ignore the virtual environment.</p>
|
|||
|
</div>
|
|||
|
<p>The created <code class="docutils literal notranslate"><span class="pre">pyvenv.cfg</span></code> file also includes the
|
|||
|
<code class="docutils literal notranslate"><span class="pre">include-system-site-packages</span></code> key, set to <code class="docutils literal notranslate"><span class="pre">true</span></code> if <code class="docutils literal notranslate"><span class="pre">venv</span></code> is
|
|||
|
run with the <code class="docutils literal notranslate"><span class="pre">--system-site-packages</span></code> option, <code class="docutils literal notranslate"><span class="pre">false</span></code> otherwise.</p>
|
|||
|
<p>Unless the <code class="docutils literal notranslate"><span class="pre">--without-pip</span></code> option is given, <a class="reference internal" href="ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the "pip" installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> will be
|
|||
|
invoked to bootstrap <code class="docutils literal notranslate"><span class="pre">pip</span></code> into the virtual environment.</p>
|
|||
|
<p>Multiple paths can be given to <code class="docutils literal notranslate"><span class="pre">venv</span></code>, in which case an identical virtual
|
|||
|
environment will be created, according to the given options, at each provided
|
|||
|
path.</p>
|
|||
|
<p>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 (<cite><venv></cite> must be replaced by the path of the
|
|||
|
directory containing the virtual environment):</p>
|
|||
|
<table class="docutils align-center">
|
|||
|
<colgroup>
|
|||
|
<col style="width: 18%" />
|
|||
|
<col style="width: 24%" />
|
|||
|
<col style="width: 58%" />
|
|||
|
</colgroup>
|
|||
|
<thead>
|
|||
|
<tr class="row-odd"><th class="head"><p>Platform</p></th>
|
|||
|
<th class="head"><p>Shell</p></th>
|
|||
|
<th class="head"><p>Command to activate virtual environment</p></th>
|
|||
|
</tr>
|
|||
|
</thead>
|
|||
|
<tbody>
|
|||
|
<tr class="row-even"><td><p>Posix</p></td>
|
|||
|
<td><p>bash/zsh</p></td>
|
|||
|
<td><p>$ source <venv>/bin/activate</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td></td>
|
|||
|
<td><p>fish</p></td>
|
|||
|
<td><p>$ . <venv>/bin/activate.fish</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td></td>
|
|||
|
<td><p>csh/tcsh</p></td>
|
|||
|
<td><p>$ source <venv>/bin/activate.csh</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-odd"><td><p>Windows</p></td>
|
|||
|
<td><p>cmd.exe</p></td>
|
|||
|
<td><p>C:\> <venv>\Scripts\activate.bat</p></td>
|
|||
|
</tr>
|
|||
|
<tr class="row-even"><td></td>
|
|||
|
<td><p>PowerShell</p></td>
|
|||
|
<td><p>PS C:\> <venv>\Scripts\Activate.ps1</p></td>
|
|||
|
</tr>
|
|||
|
</tbody>
|
|||
|
</table>
|
|||
|
<p>You don’t specifically <em>need</em> 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.</p>
|
|||
|
<p>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 <code class="docutils literal notranslate"><span class="pre">deactivate.bat</span></code> and <code class="docutils literal notranslate"><span class="pre">Deactivate.ps1</span></code> which are installed
|
|||
|
when the virtual environment is created.</p>
|
|||
|
<div class="versionadded">
|
|||
|
<p><span class="versionmodified added">New in version 3.4: </span><code class="docutils literal notranslate"><span class="pre">fish</span></code> and <code class="docutils literal notranslate"><span class="pre">csh</span></code> activation scripts.</p>
|
|||
|
</div>
|
|||
|
<div class="admonition note" id="venv-def">
|
|||
|
<p class="admonition-title">Note</p>
|
|||
|
<p>A virtual environment is a Python environment such that the Python
|
|||
|
interpreter, libraries and scripts installed into it are isolated from those
|
|||
|
installed in other virtual environments, and (by default) any libraries
|
|||
|
installed in a “system” Python, i.e., one which is installed as part of your
|
|||
|
operating system.</p>
|
|||
|
<p>A virtual environment is a directory tree which contains Python executable
|
|||
|
files and other files which indicate that it is a virtual environment.</p>
|
|||
|
<p>Common installation tools such as <code class="docutils literal notranslate"><span class="pre">Setuptools</span></code> and <code class="docutils literal notranslate"><span class="pre">pip</span></code> work as
|
|||
|
expected with virtual environments. In other words, when a virtual
|
|||
|
environment is active, they install Python packages into the virtual
|
|||
|
environment without needing to be told to do so explicitly.</p>
|
|||
|
<p>When a virtual environment is active (i.e., the virtual environment’s Python
|
|||
|
interpreter is running), the attributes <a class="reference internal" href="sys.html#sys.prefix" title="sys.prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.prefix</span></code></a> and
|
|||
|
<a class="reference internal" href="sys.html#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.exec_prefix</span></code></a> point to the base directory of the virtual
|
|||
|
environment, whereas <a class="reference internal" href="sys.html#sys.base_prefix" title="sys.base_prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.base_prefix</span></code></a> and
|
|||
|
<a class="reference internal" href="sys.html#sys.base_exec_prefix" title="sys.base_exec_prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.base_exec_prefix</span></code></a> point to the non-virtual environment Python
|
|||
|
installation which was used to create the virtual environment. If a virtual
|
|||
|
environment is not active, then <a class="reference internal" href="sys.html#sys.prefix" title="sys.prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.prefix</span></code></a> is the same as
|
|||
|
<a class="reference internal" href="sys.html#sys.base_prefix" title="sys.base_prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.base_prefix</span></code></a> and <a class="reference internal" href="sys.html#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.exec_prefix</span></code></a> is the same as
|
|||
|
<a class="reference internal" href="sys.html#sys.base_exec_prefix" title="sys.base_exec_prefix"><code class="xref py py-attr docutils literal notranslate"><span class="pre">sys.base_exec_prefix</span></code></a> (they all point to a non-virtual environment
|
|||
|
Python installation).</p>
|
|||
|
<p>When a virtual environment is active, any options that change the
|
|||
|
installation path will be ignored from all distutils configuration files to
|
|||
|
prevent projects being inadvertently installed outside of the virtual
|
|||
|
environment.</p>
|
|||
|
<p>When working in a command shell, users can make a virtual environment active
|
|||
|
by running an <code class="docutils literal notranslate"><span class="pre">activate</span></code> script in the virtual environment’s executables
|
|||
|
directory (the precise filename is shell-dependent), which prepends the
|
|||
|
virtual environment’s directory for executables to the <code class="docutils literal notranslate"><span class="pre">PATH</span></code> environment
|
|||
|
variable for the running shell. There should be no need in other
|
|||
|
circumstances to activate a virtual environment—scripts installed into
|
|||
|
virtual environments have a “shebang” line which points to the virtual
|
|||
|
environment’s Python interpreter. This means that the script will run with
|
|||
|
that interpreter regardless of the value of <code class="docutils literal notranslate"><span class="pre">PATH</span></code>. On Windows, “shebang”
|
|||
|
line processing is supported if you have the Python Launcher for Windows
|
|||
|
installed (this was added to Python in 3.3 - see <span class="target" id="index-2"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0397"><strong>PEP 397</strong></a> for more
|
|||
|
details). Thus, double-clicking an installed script in a Windows Explorer
|
|||
|
window should run the script with the correct interpreter without there
|
|||
|
needing to be any reference to its virtual environment in <code class="docutils literal notranslate"><span class="pre">PATH</span></code>.</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="section" id="api">
|
|||
|
<span id="venv-api"></span><h2>API<a class="headerlink" href="#api" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>The high-level method described above makes use of a simple API which provides
|
|||
|
mechanisms for third-party virtual environment creators to customize environment
|
|||
|
creation according to their needs, the <a class="reference internal" href="#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> class.</p>
|
|||
|
<dl class="class">
|
|||
|
<dt id="venv.EnvBuilder">
|
|||
|
<em class="property">class </em><code class="descclassname">venv.</code><code class="descname">EnvBuilder</code><span class="sig-paren">(</span><em>system_site_packages=False</em>, <em>clear=False</em>, <em>symlinks=False</em>, <em>upgrade=False</em>, <em>with_pip=False</em>, <em>prompt=None</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.EnvBuilder" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>The <a class="reference internal" href="#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> class accepts the following keyword arguments on
|
|||
|
instantiation:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">system_site_packages</span></code> – a Boolean value indicating that the system Python
|
|||
|
site-packages should be available to the environment (defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>).</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">clear</span></code> – a Boolean value which, if true, will delete the contents of
|
|||
|
any existing target directory, before creating the environment.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">symlinks</span></code> – a Boolean value indicating whether to attempt to symlink the
|
|||
|
Python binary rather than copying.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">upgrade</span></code> – a Boolean value which, if true, will upgrade an existing
|
|||
|
environment with the running Python - for use when that Python has been
|
|||
|
upgraded in-place (defaults to <code class="docutils literal notranslate"><span class="pre">False</span></code>).</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">with_pip</span></code> – a Boolean value which, if true, ensures pip is
|
|||
|
installed in the virtual environment. This uses <a class="reference internal" href="ensurepip.html#module-ensurepip" title="ensurepip: Bootstrapping the "pip" installer into an existing Python installation or virtual environment."><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code></a> with
|
|||
|
the <code class="docutils literal notranslate"><span class="pre">--default-pip</span></code> option.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">prompt</span></code> – a String to be used after virtual environment is activated
|
|||
|
(defaults to <code class="docutils literal notranslate"><span class="pre">None</span></code> which means directory name of the environment would
|
|||
|
be used).</p></li>
|
|||
|
</ul>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.4: </span>Added the <code class="docutils literal notranslate"><span class="pre">with_pip</span></code> parameter</p>
|
|||
|
</div>
|
|||
|
<div class="versionadded">
|
|||
|
<p><span class="versionmodified added">New in version 3.6: </span>Added the <code class="docutils literal notranslate"><span class="pre">prompt</span></code> parameter</p>
|
|||
|
</div>
|
|||
|
<p>Creators of third-party virtual environment tools will be free to use the
|
|||
|
provided <code class="docutils literal notranslate"><span class="pre">EnvBuilder</span></code> class as a base class.</p>
|
|||
|
<p>The returned env-builder is an object which has a method, <code class="docutils literal notranslate"><span class="pre">create</span></code>:</p>
|
|||
|
<dl class="method">
|
|||
|
<dt id="venv.EnvBuilder.create">
|
|||
|
<code class="descname">create</code><span class="sig-paren">(</span><em>env_dir</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.EnvBuilder.create" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>This method takes as required argument the path (absolute or relative to
|
|||
|
the current directory) of the target directory which is to contain the
|
|||
|
virtual environment. The <code class="docutils literal notranslate"><span class="pre">create</span></code> method will either create the
|
|||
|
environment in the specified directory, or raise an appropriate
|
|||
|
exception.</p>
|
|||
|
<p>The <code class="docutils literal notranslate"><span class="pre">create</span></code> method of the <code class="docutils literal notranslate"><span class="pre">EnvBuilder</span></code> class illustrates the hooks
|
|||
|
available for subclass customization:</p>
|
|||
|
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">create</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">env_dir</span><span class="p">):</span>
|
|||
|
<span class="sd">"""</span>
|
|||
|
<span class="sd"> Create a virtualized Python environment in a directory.</span>
|
|||
|
<span class="sd"> env_dir is the target directory to create an environment in.</span>
|
|||
|
<span class="sd"> """</span>
|
|||
|
<span class="n">env_dir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">env_dir</span><span class="p">)</span>
|
|||
|
<span class="n">context</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">ensure_directories</span><span class="p">(</span><span class="n">env_dir</span><span class="p">)</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">create_configuration</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">setup_python</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">setup_scripts</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">post_setup</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>Each of the methods <a class="reference internal" href="#venv.EnvBuilder.ensure_directories" title="venv.EnvBuilder.ensure_directories"><code class="xref py py-meth docutils literal notranslate"><span class="pre">ensure_directories()</span></code></a>,
|
|||
|
<a class="reference internal" href="#venv.EnvBuilder.create_configuration" title="venv.EnvBuilder.create_configuration"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create_configuration()</span></code></a>, <a class="reference internal" href="#venv.EnvBuilder.setup_python" title="venv.EnvBuilder.setup_python"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setup_python()</span></code></a>,
|
|||
|
<a class="reference internal" href="#venv.EnvBuilder.setup_scripts" title="venv.EnvBuilder.setup_scripts"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setup_scripts()</span></code></a> and <a class="reference internal" href="#venv.EnvBuilder.post_setup" title="venv.EnvBuilder.post_setup"><code class="xref py py-meth docutils literal notranslate"><span class="pre">post_setup()</span></code></a> can be overridden.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="method">
|
|||
|
<dt id="venv.EnvBuilder.ensure_directories">
|
|||
|
<code class="descname">ensure_directories</code><span class="sig-paren">(</span><em>env_dir</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.EnvBuilder.ensure_directories" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Creates the environment directory and all necessary directories, and
|
|||
|
returns a context object. This is just a holder for attributes (such as
|
|||
|
paths), for use by the other methods. The directories are allowed to
|
|||
|
exist already, as long as either <code class="docutils literal notranslate"><span class="pre">clear</span></code> or <code class="docutils literal notranslate"><span class="pre">upgrade</span></code> were
|
|||
|
specified to allow operating on an existing environment directory.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="method">
|
|||
|
<dt id="venv.EnvBuilder.create_configuration">
|
|||
|
<code class="descname">create_configuration</code><span class="sig-paren">(</span><em>context</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.EnvBuilder.create_configuration" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Creates the <code class="docutils literal notranslate"><span class="pre">pyvenv.cfg</span></code> configuration file in the environment.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="method">
|
|||
|
<dt id="venv.EnvBuilder.setup_python">
|
|||
|
<code class="descname">setup_python</code><span class="sig-paren">(</span><em>context</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.EnvBuilder.setup_python" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Creates a copy or symlink to the Python executable in the environment.
|
|||
|
On POSIX systems, if a specific executable <code class="docutils literal notranslate"><span class="pre">python3.x</span></code> was used,
|
|||
|
symlinks to <code class="docutils literal notranslate"><span class="pre">python</span></code> and <code class="docutils literal notranslate"><span class="pre">python3</span></code> will be created pointing to that
|
|||
|
executable, unless files with those names already exist.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="method">
|
|||
|
<dt id="venv.EnvBuilder.setup_scripts">
|
|||
|
<code class="descname">setup_scripts</code><span class="sig-paren">(</span><em>context</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.EnvBuilder.setup_scripts" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Installs activation scripts appropriate to the platform into the virtual
|
|||
|
environment.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<dl class="method">
|
|||
|
<dt id="venv.EnvBuilder.post_setup">
|
|||
|
<code class="descname">post_setup</code><span class="sig-paren">(</span><em>context</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.EnvBuilder.post_setup" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>A placeholder method which can be overridden in third party
|
|||
|
implementations to pre-install packages in the virtual environment or
|
|||
|
perform other post-creation steps.</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.7.2: </span>Windows now uses redirector scripts for <code class="docutils literal notranslate"><span class="pre">python[w].exe</span></code> instead of
|
|||
|
copying the actual binaries. In 3.7.2 only <a class="reference internal" href="#venv.EnvBuilder.setup_python" title="venv.EnvBuilder.setup_python"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setup_python()</span></code></a> does
|
|||
|
nothing unless running from a build in the source tree.</p>
|
|||
|
</div>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.7.3: </span>Windows copies the redirector scripts as part of <a class="reference internal" href="#venv.EnvBuilder.setup_python" title="venv.EnvBuilder.setup_python"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setup_python()</span></code></a>
|
|||
|
instead of <a class="reference internal" href="#venv.EnvBuilder.setup_scripts" title="venv.EnvBuilder.setup_scripts"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setup_scripts()</span></code></a>. This was not the case in 3.7.2.
|
|||
|
When using symlinks, the original executables will be linked.</p>
|
|||
|
</div>
|
|||
|
<p>In addition, <a class="reference internal" href="#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> provides this utility method that can be
|
|||
|
called from <a class="reference internal" href="#venv.EnvBuilder.setup_scripts" title="venv.EnvBuilder.setup_scripts"><code class="xref py py-meth docutils literal notranslate"><span class="pre">setup_scripts()</span></code></a> or <a class="reference internal" href="#venv.EnvBuilder.post_setup" title="venv.EnvBuilder.post_setup"><code class="xref py py-meth docutils literal notranslate"><span class="pre">post_setup()</span></code></a> in subclasses to
|
|||
|
assist in installing custom scripts into the virtual environment.</p>
|
|||
|
<dl class="method">
|
|||
|
<dt id="venv.EnvBuilder.install_scripts">
|
|||
|
<code class="descname">install_scripts</code><span class="sig-paren">(</span><em>context</em>, <em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.EnvBuilder.install_scripts" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p><em>path</em> is the path to a directory that should contain subdirectories
|
|||
|
“common”, “posix”, “nt”, each containing scripts destined for the bin
|
|||
|
directory in the environment. The contents of “common” and the
|
|||
|
directory corresponding to <a class="reference internal" href="os.html#os.name" title="os.name"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.name</span></code></a> are copied after some text
|
|||
|
replacement of placeholders:</p>
|
|||
|
<ul class="simple">
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">__VENV_DIR__</span></code> is replaced with the absolute path of the environment
|
|||
|
directory.</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">__VENV_NAME__</span></code> is replaced with the environment name (final path
|
|||
|
segment of environment directory).</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">__VENV_PROMPT__</span></code> is replaced with the prompt (the environment
|
|||
|
name surrounded by parentheses and with a following space)</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">__VENV_BIN_NAME__</span></code> is replaced with the name of the bin directory
|
|||
|
(either <code class="docutils literal notranslate"><span class="pre">bin</span></code> or <code class="docutils literal notranslate"><span class="pre">Scripts</span></code>).</p></li>
|
|||
|
<li><p><code class="docutils literal notranslate"><span class="pre">__VENV_PYTHON__</span></code> is replaced with the absolute path of the
|
|||
|
environment’s executable.</p></li>
|
|||
|
</ul>
|
|||
|
<p>The directories are allowed to exist (for when an existing environment
|
|||
|
is being upgraded).</p>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
<p>There is also a module-level convenience function:</p>
|
|||
|
<dl class="function">
|
|||
|
<dt id="venv.create">
|
|||
|
<code class="descclassname">venv.</code><code class="descname">create</code><span class="sig-paren">(</span><em>env_dir</em>, <em>system_site_packages=False</em>, <em>clear=False</em>, <em>symlinks=False</em>, <em>with_pip=False</em>, <em>prompt=None</em><span class="sig-paren">)</span><a class="headerlink" href="#venv.create" title="Permalink to this definition">¶</a></dt>
|
|||
|
<dd><p>Create an <a class="reference internal" href="#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> with the given keyword arguments, and call its
|
|||
|
<a class="reference internal" href="#venv.EnvBuilder.create" title="venv.EnvBuilder.create"><code class="xref py py-meth docutils literal notranslate"><span class="pre">create()</span></code></a> method with the <em>env_dir</em> argument.</p>
|
|||
|
<div class="versionadded">
|
|||
|
<p><span class="versionmodified added">New in version 3.3.</span></p>
|
|||
|
</div>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.4: </span>Added the <code class="docutils literal notranslate"><span class="pre">with_pip</span></code> parameter</p>
|
|||
|
</div>
|
|||
|
<div class="versionchanged">
|
|||
|
<p><span class="versionmodified changed">Changed in version 3.6: </span>Added the <code class="docutils literal notranslate"><span class="pre">prompt</span></code> parameter</p>
|
|||
|
</div>
|
|||
|
</dd></dl>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="section" id="an-example-of-extending-envbuilder">
|
|||
|
<h2>An example of extending <code class="docutils literal notranslate"><span class="pre">EnvBuilder</span></code><a class="headerlink" href="#an-example-of-extending-envbuilder" title="Permalink to this headline">¶</a></h2>
|
|||
|
<p>The following script shows how to extend <a class="reference internal" href="#venv.EnvBuilder" title="venv.EnvBuilder"><code class="xref py py-class docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a> by implementing a
|
|||
|
subclass which installs setuptools and pip into a created virtual environment:</p>
|
|||
|
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
|
|||
|
<span class="kn">import</span> <span class="nn">os.path</span>
|
|||
|
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">Popen</span><span class="p">,</span> <span class="n">PIPE</span>
|
|||
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|||
|
<span class="kn">from</span> <span class="nn">threading</span> <span class="kn">import</span> <span class="n">Thread</span>
|
|||
|
<span class="kn">from</span> <span class="nn">urllib.parse</span> <span class="kn">import</span> <span class="n">urlparse</span>
|
|||
|
<span class="kn">from</span> <span class="nn">urllib.request</span> <span class="kn">import</span> <span class="n">urlretrieve</span>
|
|||
|
<span class="kn">import</span> <span class="nn">venv</span>
|
|||
|
|
|||
|
<span class="k">class</span> <span class="nc">ExtendedEnvBuilder</span><span class="p">(</span><span class="n">venv</span><span class="o">.</span><span class="n">EnvBuilder</span><span class="p">):</span>
|
|||
|
<span class="sd">"""</span>
|
|||
|
<span class="sd"> This builder installs setuptools and pip so that you can pip or</span>
|
|||
|
<span class="sd"> easy_install other packages into the created virtual environment.</span>
|
|||
|
|
|||
|
<span class="sd"> :param nodist: If True, setuptools and pip are not installed into the</span>
|
|||
|
<span class="sd"> created virtual environment.</span>
|
|||
|
<span class="sd"> :param nopip: If True, pip is not installed into the created</span>
|
|||
|
<span class="sd"> virtual environment.</span>
|
|||
|
<span class="sd"> :param progress: If setuptools or pip are installed, the progress of the</span>
|
|||
|
<span class="sd"> installation can be monitored by passing a progress</span>
|
|||
|
<span class="sd"> callable. If specified, it is called with two</span>
|
|||
|
<span class="sd"> arguments: a string indicating some progress, and a</span>
|
|||
|
<span class="sd"> context indicating where the string is coming from.</span>
|
|||
|
<span class="sd"> The context argument can have one of three values:</span>
|
|||
|
<span class="sd"> 'main', indicating that it is called from virtualize()</span>
|
|||
|
<span class="sd"> itself, and 'stdout' and 'stderr', which are obtained</span>
|
|||
|
<span class="sd"> by reading lines from the output streams of a subprocess</span>
|
|||
|
<span class="sd"> which is used to install the app.</span>
|
|||
|
|
|||
|
<span class="sd"> If a callable is not specified, default progress</span>
|
|||
|
<span class="sd"> information is output to sys.stderr.</span>
|
|||
|
<span class="sd"> """</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">nodist</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">'nodist'</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">nopip</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">'nopip'</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">progress</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">'progress'</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">verbose</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">'verbose'</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
|
|||
|
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">post_setup</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
|
|||
|
<span class="sd">"""</span>
|
|||
|
<span class="sd"> Set up any packages which need to be pre-installed into the</span>
|
|||
|
<span class="sd"> virtual environment being created.</span>
|
|||
|
|
|||
|
<span class="sd"> :param context: The information for the virtual environment</span>
|
|||
|
<span class="sd"> creation request being processed.</span>
|
|||
|
<span class="sd"> """</span>
|
|||
|
<span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">'VIRTUAL_ENV'</span><span class="p">]</span> <span class="o">=</span> <span class="n">context</span><span class="o">.</span><span class="n">env_dir</span>
|
|||
|
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodist</span><span class="p">:</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">install_setuptools</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
|
|||
|
<span class="c1"># Can't install pip without setuptools</span>
|
|||
|
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">nopip</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">nodist</span><span class="p">:</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">install_pip</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">reader</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">stream</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
|
|||
|
<span class="sd">"""</span>
|
|||
|
<span class="sd"> Read lines from a subprocess' output stream and either pass to a progress</span>
|
|||
|
<span class="sd"> callable (if specified) or write progress information to sys.stderr.</span>
|
|||
|
<span class="sd"> """</span>
|
|||
|
<span class="n">progress</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">progress</span>
|
|||
|
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
|
|||
|
<span class="n">s</span> <span class="o">=</span> <span class="n">stream</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span>
|
|||
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">s</span><span class="p">:</span>
|
|||
|
<span class="k">break</span>
|
|||
|
<span class="k">if</span> <span class="n">progress</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
|
|||
|
<span class="n">progress</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">context</span><span class="p">)</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span><span class="p">:</span>
|
|||
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'.'</span><span class="p">)</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'utf-8'</span><span class="p">))</span>
|
|||
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
|
|||
|
<span class="n">stream</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">install_script</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">url</span><span class="p">):</span>
|
|||
|
<span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">urlparse</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
|
|||
|
<span class="n">fn</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">path</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
|
|||
|
<span class="n">binpath</span> <span class="o">=</span> <span class="n">context</span><span class="o">.</span><span class="n">bin_path</span>
|
|||
|
<span class="n">distpath</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">binpath</span><span class="p">,</span> <span class="n">fn</span><span class="p">)</span>
|
|||
|
<span class="c1"># Download script into the virtual environment's binaries folder</span>
|
|||
|
<span class="n">urlretrieve</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">distpath</span><span class="p">)</span>
|
|||
|
<span class="n">progress</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">progress</span>
|
|||
|
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">verbose</span><span class="p">:</span>
|
|||
|
<span class="n">term</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\n</span><span class="s1">'</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="n">term</span> <span class="o">=</span> <span class="s1">''</span>
|
|||
|
<span class="k">if</span> <span class="n">progress</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
|
|||
|
<span class="n">progress</span><span class="p">(</span><span class="s1">'Installing </span><span class="si">%s</span><span class="s1"> ...</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">term</span><span class="p">),</span> <span class="s1">'main'</span><span class="p">)</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'Installing </span><span class="si">%s</span><span class="s1"> ...</span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">term</span><span class="p">))</span>
|
|||
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
|
|||
|
<span class="c1"># Install in the virtual environment</span>
|
|||
|
<span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="n">context</span><span class="o">.</span><span class="n">env_exe</span><span class="p">,</span> <span class="n">fn</span><span class="p">]</span>
|
|||
|
<span class="n">p</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">cwd</span><span class="o">=</span><span class="n">binpath</span><span class="p">)</span>
|
|||
|
<span class="n">t1</span> <span class="o">=</span> <span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">reader</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span> <span class="s1">'stdout'</span><span class="p">))</span>
|
|||
|
<span class="n">t1</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
|||
|
<span class="n">t2</span> <span class="o">=</span> <span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">reader</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">stderr</span><span class="p">,</span> <span class="s1">'stderr'</span><span class="p">))</span>
|
|||
|
<span class="n">t2</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
|
|||
|
<span class="n">p</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
|
|||
|
<span class="n">t1</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
|
|||
|
<span class="n">t2</span><span class="o">.</span><span class="n">join</span><span class="p">()</span>
|
|||
|
<span class="k">if</span> <span class="n">progress</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
|
|||
|
<span class="n">progress</span><span class="p">(</span><span class="s1">'done.'</span><span class="p">,</span> <span class="s1">'main'</span><span class="p">)</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">'done.</span><span class="se">\n</span><span class="s1">'</span><span class="p">)</span>
|
|||
|
<span class="c1"># Clean up - no longer needed</span>
|
|||
|
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">distpath</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">install_setuptools</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
|
|||
|
<span class="sd">"""</span>
|
|||
|
<span class="sd"> Install setuptools in the virtual environment.</span>
|
|||
|
|
|||
|
<span class="sd"> :param context: The information for the virtual environment</span>
|
|||
|
<span class="sd"> creation request being processed.</span>
|
|||
|
<span class="sd"> """</span>
|
|||
|
<span class="n">url</span> <span class="o">=</span> <span class="s1">'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py'</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">install_script</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="s1">'setuptools'</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
|
|||
|
<span class="c1"># clear up the setuptools archive which gets downloaded</span>
|
|||
|
<span class="n">pred</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">o</span><span class="p">:</span> <span class="n">o</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">'setuptools-'</span><span class="p">)</span> <span class="ow">and</span> <span class="n">o</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">'.tar.gz'</span><span class="p">)</span>
|
|||
|
<span class="n">files</span> <span class="o">=</span> <span class="nb">filter</span><span class="p">(</span><span class="n">pred</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">bin_path</span><span class="p">))</span>
|
|||
|
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
|
|||
|
<span class="n">f</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">context</span><span class="o">.</span><span class="n">bin_path</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
|
|||
|
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">install_pip</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
|
|||
|
<span class="sd">"""</span>
|
|||
|
<span class="sd"> Install pip in the virtual environment.</span>
|
|||
|
|
|||
|
<span class="sd"> :param context: The information for the virtual environment</span>
|
|||
|
<span class="sd"> creation request being processed.</span>
|
|||
|
<span class="sd"> """</span>
|
|||
|
<span class="n">url</span> <span class="o">=</span> <span class="s1">'https://raw.github.com/pypa/pip/master/contrib/get-pip.py'</span>
|
|||
|
<span class="bp">self</span><span class="o">.</span><span class="n">install_script</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="s1">'pip'</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">args</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
|
|||
|
<span class="n">compatible</span> <span class="o">=</span> <span class="bp">True</span>
|
|||
|
<span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span> <span class="o"><</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">3</span><span class="p">):</span>
|
|||
|
<span class="n">compatible</span> <span class="o">=</span> <span class="bp">False</span>
|
|||
|
<span class="k">elif</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">sys</span><span class="p">,</span> <span class="s1">'base_prefix'</span><span class="p">):</span>
|
|||
|
<span class="n">compatible</span> <span class="o">=</span> <span class="bp">False</span>
|
|||
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">compatible</span><span class="p">:</span>
|
|||
|
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'This script is only for use with '</span>
|
|||
|
<span class="s1">'Python 3.3 or later'</span><span class="p">)</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="kn">import</span> <span class="nn">argparse</span>
|
|||
|
|
|||
|
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">prog</span><span class="o">=</span><span class="vm">__name__</span><span class="p">,</span>
|
|||
|
<span class="n">description</span><span class="o">=</span><span class="s1">'Creates virtual Python '</span>
|
|||
|
<span class="s1">'environments in one or '</span>
|
|||
|
<span class="s1">'more target '</span>
|
|||
|
<span class="s1">'directories.'</span><span class="p">)</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'dirs'</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s1">'ENV_DIR'</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="s1">'+'</span><span class="p">,</span>
|
|||
|
<span class="n">help</span><span class="o">=</span><span class="s1">'A directory in which to create the</span>
|
|||
|
<span class="s1">'virtual environment.'</span><span class="p">)</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--no-setuptools'</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
|
|||
|
<span class="n">action</span><span class="o">=</span><span class="s1">'store_true'</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s1">'nodist'</span><span class="p">,</span>
|
|||
|
<span class="n">help</span><span class="o">=</span><span class="s2">"Don't install setuptools or pip in the "</span>
|
|||
|
<span class="s2">"virtual environment."</span><span class="p">)</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--no-pip'</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
|
|||
|
<span class="n">action</span><span class="o">=</span><span class="s1">'store_true'</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s1">'nopip'</span><span class="p">,</span>
|
|||
|
<span class="n">help</span><span class="o">=</span><span class="s2">"Don't install pip in the virtual "</span>
|
|||
|
<span class="s2">"environment."</span><span class="p">)</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--system-site-packages'</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
|
|||
|
<span class="n">action</span><span class="o">=</span><span class="s1">'store_true'</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s1">'system_site'</span><span class="p">,</span>
|
|||
|
<span class="n">help</span><span class="o">=</span><span class="s1">'Give the virtual environment access to the '</span>
|
|||
|
<span class="s1">'system site-packages dir.'</span><span class="p">)</span>
|
|||
|
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">'nt'</span><span class="p">:</span>
|
|||
|
<span class="n">use_symlinks</span> <span class="o">=</span> <span class="bp">False</span>
|
|||
|
<span class="k">else</span><span class="p">:</span>
|
|||
|
<span class="n">use_symlinks</span> <span class="o">=</span> <span class="bp">True</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--symlinks'</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="n">use_symlinks</span><span class="p">,</span>
|
|||
|
<span class="n">action</span><span class="o">=</span><span class="s1">'store_true'</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s1">'symlinks'</span><span class="p">,</span>
|
|||
|
<span class="n">help</span><span class="o">=</span><span class="s1">'Try to use symlinks rather than copies, '</span>
|
|||
|
<span class="s1">'when symlinks are not the default for '</span>
|
|||
|
<span class="s1">'the platform.'</span><span class="p">)</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--clear'</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'store_true'</span><span class="p">,</span>
|
|||
|
<span class="n">dest</span><span class="o">=</span><span class="s1">'clear'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Delete the contents of the '</span>
|
|||
|
<span class="s1">'virtual environment '</span>
|
|||
|
<span class="s1">'directory if it already '</span>
|
|||
|
<span class="s1">'exists, before virtual '</span>
|
|||
|
<span class="s1">'environment creation.'</span><span class="p">)</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--upgrade'</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'store_true'</span><span class="p">,</span>
|
|||
|
<span class="n">dest</span><span class="o">=</span><span class="s1">'upgrade'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Upgrade the virtual '</span>
|
|||
|
<span class="s1">'environment directory to '</span>
|
|||
|
<span class="s1">'use this version of '</span>
|
|||
|
<span class="s1">'Python, assuming Python '</span>
|
|||
|
<span class="s1">'has been upgraded '</span>
|
|||
|
<span class="s1">'in-place.'</span><span class="p">)</span>
|
|||
|
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">'--verbose'</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">'store_true'</span><span class="p">,</span>
|
|||
|
<span class="n">dest</span><span class="o">=</span><span class="s1">'verbose'</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">'Display the output '</span>
|
|||
|
<span class="s1">'from the scripts which '</span>
|
|||
|
<span class="s1">'install setuptools and pip.'</span><span class="p">)</span>
|
|||
|
<span class="n">options</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
|
|||
|
<span class="k">if</span> <span class="n">options</span><span class="o">.</span><span class="n">upgrade</span> <span class="ow">and</span> <span class="n">options</span><span class="o">.</span><span class="n">clear</span><span class="p">:</span>
|
|||
|
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">'you cannot supply --upgrade and --clear together.'</span><span class="p">)</span>
|
|||
|
<span class="n">builder</span> <span class="o">=</span> <span class="n">ExtendedEnvBuilder</span><span class="p">(</span><span class="n">system_site_packages</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">system_site</span><span class="p">,</span>
|
|||
|
<span class="n">clear</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">clear</span><span class="p">,</span>
|
|||
|
<span class="n">symlinks</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">symlinks</span><span class="p">,</span>
|
|||
|
<span class="n">upgrade</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">upgrade</span><span class="p">,</span>
|
|||
|
<span class="n">nodist</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">nodist</span><span class="p">,</span>
|
|||
|
<span class="n">nopip</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">nopip</span><span class="p">,</span>
|
|||
|
<span class="n">verbose</span><span class="o">=</span><span class="n">options</span><span class="o">.</span><span class="n">verbose</span><span class="p">)</span>
|
|||
|
<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">options</span><span class="o">.</span><span class="n">dirs</span><span class="p">:</span>
|
|||
|
<span class="n">builder</span><span class="o">.</span><span class="n">create</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
|
|||
|
|
|||
|
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s1">'__main__'</span><span class="p">:</span>
|
|||
|
<span class="n">rc</span> <span class="o">=</span> <span class="mi">1</span>
|
|||
|
<span class="k">try</span><span class="p">:</span>
|
|||
|
<span class="n">main</span><span class="p">()</span>
|
|||
|
<span class="n">rc</span> <span class="o">=</span> <span class="mi">0</span>
|
|||
|
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|||
|
<span class="k">print</span><span class="p">(</span><span class="s1">'Error: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">e</span><span class="p">,</span> <span class="nb">file</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="p">)</span>
|
|||
|
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">rc</span><span class="p">)</span>
|
|||
|
</pre></div>
|
|||
|
</div>
|
|||
|
<p>This script is also available for download <a class="reference external" href="https://gist.github.com/vsajip/4673395">online</a>.</p>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
|||
|
<div class="sphinxsidebarwrapper">
|
|||
|
<h3><a href="../contents.html">Table of Contents</a></h3>
|
|||
|
<ul>
|
|||
|
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">venv</span></code> — Creation of virtual environments</a><ul>
|
|||
|
<li><a class="reference internal" href="#creating-virtual-environments">Creating virtual environments</a></li>
|
|||
|
<li><a class="reference internal" href="#api">API</a></li>
|
|||
|
<li><a class="reference internal" href="#an-example-of-extending-envbuilder">An example of extending <code class="docutils literal notranslate"><span class="pre">EnvBuilder</span></code></a></li>
|
|||
|
</ul>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<h4>Previous topic</h4>
|
|||
|
<p class="topless"><a href="ensurepip.html"
|
|||
|
title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ensurepip</span></code> — Bootstrapping the <code class="docutils literal notranslate"><span class="pre">pip</span></code> installer</a></p>
|
|||
|
<h4>Next topic</h4>
|
|||
|
<p class="topless"><a href="zipapp.html"
|
|||
|
title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipapp</span></code> — Manage executable Python zip archives</a></p>
|
|||
|
<div role="note" aria-label="source link">
|
|||
|
<h3>This Page</h3>
|
|||
|
<ul class="this-page-menu">
|
|||
|
<li><a href="../bugs.html">Report a Bug</a></li>
|
|||
|
<li>
|
|||
|
<a href="https://github.com/python/cpython/blob/3.7/Doc/library/venv.rst"
|
|||
|
rel="nofollow">Show Source
|
|||
|
</a>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
<div class="clearer"></div>
|
|||
|
</div>
|
|||
|
<div class="related" role="navigation" aria-label="related navigation">
|
|||
|
<h3>Navigation</h3>
|
|||
|
<ul>
|
|||
|
<li class="right" style="margin-right: 10px">
|
|||
|
<a href="../genindex.html" title="General Index"
|
|||
|
>index</a></li>
|
|||
|
<li class="right" >
|
|||
|
<a href="../py-modindex.html" title="Python Module Index"
|
|||
|
>modules</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="zipapp.html" title="zipapp — Manage executable Python zip archives"
|
|||
|
>next</a> |</li>
|
|||
|
<li class="right" >
|
|||
|
<a href="ensurepip.html" title="ensurepip — Bootstrapping the pip installer"
|
|||
|
>previous</a> |</li>
|
|||
|
<li><img src="../_static/py.png" alt=""
|
|||
|
style="vertical-align: middle; margin-top: -1px"/></li>
|
|||
|
<li><a href="https://www.python.org/">Python</a> »</li>
|
|||
|
<li>
|
|||
|
<span class="language_switcher_placeholder">en</span>
|
|||
|
<span class="version_switcher_placeholder">3.7.4</span>
|
|||
|
<a href="../index.html">Documentation </a> »
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
|
|||
|
<li class="nav-item nav-item-2"><a href="distribution.html" >Software Packaging and Distribution</a> »</li>
|
|||
|
<li class="right">
|
|||
|
|
|||
|
|
|||
|
<div class="inline-search" style="display: none" role="search">
|
|||
|
<form class="inline-search" action="../search.html" method="get">
|
|||
|
<input placeholder="Quick search" type="text" name="q" />
|
|||
|
<input type="submit" value="Go" />
|
|||
|
<input type="hidden" name="check_keywords" value="yes" />
|
|||
|
<input type="hidden" name="area" value="default" />
|
|||
|
</form>
|
|||
|
</div>
|
|||
|
<script type="text/javascript">$('.inline-search').show(0);</script>
|
|||
|
|
|
|||
|
</li>
|
|||
|
|
|||
|
</ul>
|
|||
|
</div>
|
|||
|
<div class="footer">
|
|||
|
© <a href="../copyright.html">Copyright</a> 2001-2019, Python Software Foundation.
|
|||
|
<br />
|
|||
|
The Python Software Foundation is a non-profit corporation.
|
|||
|
<a href="https://www.python.org/psf/donations/">Please donate.</a>
|
|||
|
<br />
|
|||
|
Last updated on Jul 13, 2019.
|
|||
|
<a href="../bugs.html">Found a bug</a>?
|
|||
|
<br />
|
|||
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.0.1.
|
|||
|
</div>
|
|||
|
|
|||
|
</body>
|
|||
|
</html>
|