linuxOS_AP05/debian/test/usr/share/doc/python3/python-policy.html/programs.html
2025-09-26 09:40:02 +08:00

61 lines
6.9 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter 4. Python Programs</title><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="home" href="index.html" title="Debian Python Policy" /><link rel="up" href="index.html" title="Debian Python Policy" /><link rel="prev" href="module_packages.html" title="Chapter 3. Packaged Modules" /><link rel="next" href="embed.html" title="Chapter 5. Programs Embedding Python" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 4. Python Programs</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="module_packages.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="embed.html">Next</a></td></tr></table><hr /></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="programs"></a>Chapter 4. Python Programs</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="section"><a href="programs.html#interpreter-directive">4.1. Interpreter directive (“Shebang”)</a></span></dt><dt><span class="section"><a href="programs.html#version_indep_progs">4.2. Programs using the default Python</a></span></dt><dd><dl><dt><span class="section"><a href="programs.html#current_version_progs">4.2.1. Programs Shipping Private Modules</a></span></dt></dl></dd><dt><span class="section"><a href="programs.html#version_dep_progs">4.3. Programs Using a Particular Python Version</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="interpreter-directive"></a>4.1. Interpreter directive (“Shebang”)</h2></div></div></div><p>
Executables written for interpretation by Python must use an
appropraite interpreter directive, or “shebang”, as the first line
of the program. This line should be of the
form <code class="literal">#!<em class="replaceable"><code>interpreter_location</code></em></code>.
See <a class="xref" href="python.html#interpreter_name" title="2.4.1. Interpreter Name">Section 2.4.1, “Interpreter Name”</a> for the interpreter name to use.
</p><p>
As noted in <a class="xref" href="python.html#interpreter_loc" title="2.4.2. Interpreter Location">Section 2.4.2, “Interpreter Location”</a>, the
form <code class="literal">#!/usr/bin/env <em class="replaceable"><code>interpreter_name</code></em></code> is
deprecated.
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="version_indep_progs"></a>4.2. Programs using the default Python</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="programs.html#current_version_progs">4.2.1. Programs Shipping Private Modules</a></span></dt></dl></div><p>
A package that installs a program that can be run by any version
of Python 3 must declare a dependency
on <code class="literal">python3</code>, with a versioned dependency if
necessary.
</p><p>
A package that installs a program that can be run by any version
of Python 2 must declare a dependency
on <code class="literal">python2</code>, with a versioned dependency if
necessary.
</p><p>
If the program needs the public Python module <code class="literal">foo</code>, the
package must depend on the binary package that installs
the <code class="literal">foo</code> module. See <a class="xref" href="module_packages.html#package_names" title="3.3. Module Package Names">Section 3.3, “Module Package Names”</a> for the
naming of packages that install public Python modules.
</p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="current_version_progs"></a>4.2.1. Programs Shipping Private Modules</h3></div></div></div><p>
A program that specifies <code class="filename">python3</code>
or <code class="filename">python</code> as its interpreter may require its own
private Python modules. These modules should be installed
in <code class="filename">/usr/share/<em class="replaceable"><code>module</code></em></code>, or
<code class="filename">/usr/lib/<em class="replaceable"><code>module</code></em></code> if the modules are
architecture-dependent (e.g. extensions).
</p><p>
The rules explained in <a class="xref" href="module_packages.html#byte_compilation" title="3.7. Modules Byte-Compilation">Section 3.7, “Modules Byte-Compilation”</a> apply to
those private modules: the byte-compiled modules must not be
shipped with the binary package, they should be generated in the
package's post-install script using the current default Python
version, and removed in the pre-remove script. Modules should be
byte-compiled using the current default Python version.
</p><p>
Programs that have private compiled extensions must either
handle multiple version support themselves, or declare a tight
dependency on the current Python version (e.g. <code class="literal">Depends:
python3 (&gt;= 3.5),
python3 (&lt;&lt; 3.6)</code>.
</p></div></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="version_dep_progs"></a>4.3. Programs Using a Particular Python Version</h2></div></div></div><p>
A program which requires a specific minor version of Python must
specify the versioned
interpreter <code class="filename">python<em class="replaceable"><code>X</code></em>.<em class="replaceable"><code>Y</code></em></code>. The
package that installs the programs must also specify a dependency
on
<code class="literal">python<em class="replaceable"><code>X</code></em>.<em class="replaceable"><code>Y</code></em></code> and on any
packages that install necessary modules.
</p><p>
The notes on installation directories and byte-compilation
for programs that support any version of Python also apply
to programs supporting only a single Python version. Modules
to be byte-compiled should use the same Python version as the
package itself.
</p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="module_packages.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="embed.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 3. Packaged Modules </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 5. Programs Embedding Python</td></tr></table></div></body></html>