[code.view]

[top] / python / PyMOTW / docs / sysconfig / index.html


<!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>sysconfig – Interpreter Compile-time Configuration &mdash; Python Module of the Week</title>
    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.132',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </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>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="top" title="Python Module of the Week" href="../index.html" />
    <link rel="up" title="Python Runtime Services" href="../runtime_services.html" />
    <link rel="next" title="traceback – Extract, format, and print exceptions and stack traces." href="../traceback/index.html" />
    <link rel="prev" title="Modules and Imports" href="../sys/imports.html" /> 
  </head>
  <body>
    <div class="related">
      <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="../traceback/index.html" title="traceback – Extract, format, and print exceptions and stack traces."
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="../sys/imports.html" title="Modules and Imports"
             accesskey="P">previous</a> |</li>
        <li><a href="../contents.html">PyMOTW</a> &raquo;</li>
          <li><a href="../runtime_services.html" accesskey="U">Python Runtime Services</a> &raquo;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">sysconfig &#8211; Interpreter Compile-time Configuration</a><ul>
<li><a class="reference internal" href="#configuration-variables">Configuration Variables</a></li>
<li><a class="reference internal" href="#installation-paths">Installation Paths</a></li>
<li><a class="reference internal" href="#python-version-and-platform">Python Version and Platform</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="../sys/imports.html"
                        title="previous chapter">Modules and Imports</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../traceback/index.html"
                        title="next chapter">traceback &#8211; Extract, format, and print exceptions and stack traces.</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/sysconfig/index.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-sysconfig">
<span id="sysconfig-interpreter-compile-time-configuration"></span><h1>sysconfig &#8211; Interpreter Compile-time Configuration<a class="headerlink" href="#module-sysconfig" title="Permalink to this headline">¶</a></h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Purpose:</th><td class="field-body">Access the configuration settings used to build Python.</td>
</tr>
<tr class="field"><th class="field-name">Python Version:</th><td class="field-body">2.7 and later</td>
</tr>
</tbody>
</table>
<p>In Python 2.7 <a class="reference internal" href="#module-sysconfig" title="sysconfig: Interpreter Compile-time Configuration"><tt class="xref py py-mod docutils literal"><span class="pre">sysconfig</span></tt></a> has been extracted from
<tt class="xref py py-mod docutils literal"><span class="pre">distutils</span></tt> to become a stand-alone module.  It includes
functions for determining the settings used to compile and install the
current interpreter.</p>
<div class="section" id="configuration-variables">
<h2>Configuration Variables<a class="headerlink" href="#configuration-variables" title="Permalink to this headline">¶</a></h2>
<p>You can access the build-time configuration settings through two
functions.  <tt class="xref py py-func docutils literal"><span class="pre">get_config_vars()</span></tt> returns a dictionary mapping the
configuration variable names to values.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>

<span class="n">config_values</span> <span class="o">=</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_config_vars</span><span class="p">()</span>
<span class="k">print</span> <span class="s">&#39;Found </span><span class="si">%d</span><span class="s"> configuration settings&#39;</span> <span class="o">%</span> <span class="nb">len</span><span class="p">(</span><span class="n">config_values</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<span class="k">print</span>

<span class="k">print</span> <span class="s">&#39;Some highlights:&#39;</span>

<span class="k">print</span>
<span class="k">print</span> <span class="s">&#39;  Installation prefixes:&#39;</span>
<span class="k">print</span> <span class="s">&#39;    prefix={prefix}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;    exec_prefix={exec_prefix}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>

<span class="k">print</span>
<span class="k">print</span> <span class="s">&#39;  Version info:&#39;</span>
<span class="k">print</span> <span class="s">&#39;    py_version={py_version}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;    py_version_short={py_version_short}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;    py_version_nodot={py_version_nodot}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>

<span class="k">print</span>
<span class="k">print</span> <span class="s">&#39;  Base directories:&#39;</span>
<span class="k">print</span> <span class="s">&#39;    base={base}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;    platbase={platbase}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;    userbase={userbase}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;    srcdir={srcdir}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>

<span class="k">print</span>
<span class="k">print</span> <span class="s">&#39;  Compiler and linker flags:&#39;</span>
<span class="k">print</span> <span class="s">&#39;    LDFLAGS={LDFLAGS}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;    BASECFLAGS={BASECFLAGS}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;    Py_ENABLE_SHARED={Py_ENABLE_SHARED}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">config_values</span><span class="p">)</span>
</pre></div>
</div>
<p>The level of detail available through the <a class="reference internal" href="#module-sysconfig" title="sysconfig: Interpreter Compile-time Configuration"><tt class="xref py py-mod docutils literal"><span class="pre">sysconfig</span></tt></a> API depends
on the platform where your program is running.  On POSIX systems such
as Linux and OS X, the <tt class="docutils literal"><span class="pre">Makefile</span></tt> used to build the interpreter and
<tt class="docutils literal"><span class="pre">config.h</span></tt> header file generated for the build are parsed and all of
the variables found within are available.  On non-POSIX-compliant
systems such as Windows, the settings are limited to a few paths,
filename extensions, and version details.</p>
<div class="highlight-python"><pre>$ python sysconfig_get_config_vars.py

Found 511 configuration settings

Some highlights:

  Installation prefixes:
    prefix=/Library/Frameworks/Python.framework/Versions/2.7
    exec_prefix=/Library/Frameworks/Python.framework/Versions/2.7

  Version info:
    py_version=2.7
    py_version_short=2.7
    py_version_nodot=27

  Base directories:
    base=/Users/dhellmann/.virtualenvs/pymotw
    platbase=/Users/dhellmann/.virtualenvs/pymotw
    userbase=/Users/dhellmann/Library/Python/2.7
    srcdir=/Users/sysadmin/X/r27

  Compiler and linker flags:
    LDFLAGS=-arch i386 -arch ppc -arch x86_64 -isysroot / -g
    BASECFLAGS=-fno-strict-aliasing -fno-common -dynamic
    Py_ENABLE_SHARED=0</pre>
</div>
<p>If you pass variable names to <tt class="xref py py-func docutils literal"><span class="pre">get_config_vars()</span></tt>, the return
value is a <tt class="xref py py-class docutils literal"><span class="pre">list</span></tt> created by appending all of the values for
those variables together.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>

<span class="n">bases</span> <span class="o">=</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_config_vars</span><span class="p">(</span><span class="s">&#39;base&#39;</span><span class="p">,</span> <span class="s">&#39;platbase&#39;</span><span class="p">,</span> <span class="s">&#39;userbase&#39;</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;Base directories:&#39;</span>
<span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">bases</span><span class="p">:</span>
    <span class="k">print</span> <span class="s">&#39;  &#39;</span><span class="p">,</span> <span class="n">b</span>
</pre></div>
</div>
<p>This example builds a list of all of the installation base directories
where modules can be found on the current system.</p>
<div class="highlight-python"><pre>$ python sysconfig_get_config_vars_by_name.py

Base directories:
   /Users/dhellmann/.virtualenvs/pymotw
   /Users/dhellmann/.virtualenvs/pymotw
   /Users/dhellmann/Library/Python/2.7</pre>
</div>
<p>When you only need a single configuration value, use
<tt class="xref py py-func docutils literal"><span class="pre">get_config_var()</span></tt> to retrieve it.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>

<span class="k">print</span> <span class="s">&#39;User base directory:&#39;</span><span class="p">,</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_config_var</span><span class="p">(</span><span class="s">&#39;userbase&#39;</span><span class="p">)</span>
<span class="k">print</span> <span class="s">&#39;Unknown variable   :&#39;</span><span class="p">,</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_config_var</span><span class="p">(</span><span class="s">&#39;NoSuchVariable&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>If the variable is not found, <tt class="xref py py-func docutils literal"><span class="pre">get_config_var()</span></tt> returns <tt class="xref docutils literal"><span class="pre">None</span></tt>
instead of raising an exception.</p>
<div class="highlight-python"><pre>$ python sysconfig_get_config_var.py

User base directory: /Users/dhellmann/Library/Python/2.7
Unknown variable   : None</pre>
</div>
</div>
<div class="section" id="installation-paths">
<h2>Installation Paths<a class="headerlink" href="#installation-paths" title="Permalink to this headline">¶</a></h2>
<p><a class="reference internal" href="#module-sysconfig" title="sysconfig: Interpreter Compile-time Configuration"><tt class="xref py py-mod docutils literal"><span class="pre">sysconfig</span></tt></a> is primarily meant to be used by installation and
packaging tools.  As a result, while it provides access to general
configuration settings such as the interpreter version, it is
primarily focused on the information needed to locate parts of the
Python distribution currently installed on a system.  The locations
used by for installing a package depend on the <em>scheme</em> used.</p>
<p>A scheme is a set of platform-specific default directories organized
based on the platform&#8217;s packaging standards and guidelines.  There are
different schemes for installing into a site-wide location or a
private directory owned by the user.  The full set of schemes can be
accessed with <tt class="xref py py-func docutils literal"><span class="pre">get_scheme_names()</span></tt>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>

<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_scheme_names</span><span class="p">():</span>
    <span class="k">print</span> <span class="n">name</span>
</pre></div>
</div>
<p>There is no concept of a &#8220;current scheme&#8221; per se.  The default scheme
depends on the platform, and the actual scheme used depends on options
given to the installation program.  If the current system is running a
POSIX-compliant operating system, the default is <tt class="docutils literal"><span class="pre">posix_prefix</span></tt>.
Otherwise the default is <tt class="docutils literal"><span class="pre">os.name</span></tt>.</p>
<div class="highlight-python"><pre>$ python sysconfig_get_scheme_names.py

nt
nt_user
os2
os2_home
osx_framework_user
posix_home
posix_prefix
posix_user</pre>
</div>
<p>Each scheme defines a set of paths used for installing packages.  For
a list of the path names, use <tt class="xref py py-func docutils literal"><span class="pre">get_path_names()</span></tt>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>

<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_path_names</span><span class="p">():</span>
    <span class="k">print</span> <span class="n">name</span>
</pre></div>
</div>
<p>Some of the paths may be the same for a given scheme, but installers
should not make any assumptions about what the actual paths are.  Each
name has a particular semantic meaning, so the correct name should be
used to find the path for a given file during installation.</p>
<table border="1" class="docutils">
<colgroup>
<col width="17%" />
<col width="83%" />
</colgroup>
<thead valign="bottom">
<tr><th class="head">Name</th>
<th class="head">Description</th>
</tr>
</thead>
<tbody valign="top">
<tr><td>stdlib</td>
<td>Standard Python library files, not platform-specific</td>
</tr>
<tr><td>platstdlib</td>
<td>Standard Python library files, platform-specific</td>
</tr>
<tr><td>platlib</td>
<td>Site-specific, platform-specific files</td>
</tr>
<tr><td>purelib</td>
<td>Site-specific, non-platform-specific files</td>
</tr>
<tr><td>include</td>
<td>Header files, not platform-specific</td>
</tr>
<tr><td>platinclude</td>
<td>Header files, platform-specific</td>
</tr>
<tr><td>scripts</td>
<td>Executable script files</td>
</tr>
<tr><td>data</td>
<td>Data files</td>
</tr>
</tbody>
</table>
<div class="highlight-python"><pre>$ python sysconfig_get_path_names.py

stdlib
platstdlib
purelib
platlib
include
scripts
data</pre>
</div>
<p>Use <tt class="xref py py-func docutils literal"><span class="pre">get_paths()</span></tt> to retrieve the actual directories associated
with a scheme.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>
<span class="kn">import</span> <span class="nn">pprint</span>

<span class="k">for</span> <span class="n">scheme</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;posix_prefix&#39;</span><span class="p">,</span> <span class="s">&#39;posix_user&#39;</span><span class="p">]:</span>
    <span class="k">print</span> <span class="n">scheme</span>
    <span class="k">print</span> <span class="s">&#39;=&#39;</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">scheme</span><span class="p">)</span>
    <span class="n">pprint</span><span class="o">.</span><span class="n">pprint</span><span class="p">(</span><span class="n">sysconfig</span><span class="o">.</span><span class="n">get_paths</span><span class="p">(</span><span class="n">scheme</span><span class="o">=</span><span class="n">scheme</span><span class="p">))</span>
    <span class="k">print</span> 
</pre></div>
</div>
<p>This example shows the difference between the system-wide paths uses
for <tt class="docutils literal"><span class="pre">posix_prefix</span></tt> and the user-specific values for <tt class="docutils literal"><span class="pre">posix_user</span></tt>.</p>
<div class="highlight-python"><pre>$ python sysconfig_get_paths.py

posix_prefix
============
{'data': '/Users/dhellmann/.virtualenvs/pymotw',
 'include': '/Users/dhellmann/.virtualenvs/pymotw/include/python2.7',
 'platinclude': '/Users/dhellmann/.virtualenvs/pymotw/include/python2.7',
 'platlib': '/Users/dhellmann/.virtualenvs/pymotw/lib/python2.7/site-packages',
 'platstdlib': '/Users/dhellmann/.virtualenvs/pymotw/lib/python2.7',
 'purelib': '/Users/dhellmann/.virtualenvs/pymotw/lib/python2.7/site-packages',
 'scripts': '/Users/dhellmann/.virtualenvs/pymotw/bin',
 'stdlib': '/Users/dhellmann/.virtualenvs/pymotw/lib/python2.7'}

posix_user
==========
{'data': '/Users/dhellmann/Library/Python/2.7',
 'include': '/Users/dhellmann/Library/Python/2.7/include/python2.7',
 'platlib': '/Users/dhellmann/Library/Python/2.7/lib/python2.7/site-packages',
 'platstdlib': '/Users/dhellmann/Library/Python/2.7/lib/python2.7',
 'purelib': '/Users/dhellmann/Library/Python/2.7/lib/python2.7/site-packages',
 'scripts': '/Users/dhellmann/Library/Python/2.7/bin',
 'stdlib': '/Users/dhellmann/Library/Python/2.7/lib/python2.7'}</pre>
</div>
<p>For an individual path, call <tt class="xref py py-func docutils literal"><span class="pre">get_path()</span></tt>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>
<span class="kn">import</span> <span class="nn">pprint</span>

<span class="k">for</span> <span class="n">scheme</span> <span class="ow">in</span> <span class="p">[</span><span class="s">&#39;posix_prefix&#39;</span><span class="p">,</span> <span class="s">&#39;posix_user&#39;</span><span class="p">]:</span>
    <span class="k">print</span> <span class="n">scheme</span>
    <span class="k">print</span> <span class="s">&#39;=&#39;</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">scheme</span><span class="p">)</span>
    <span class="k">print</span> <span class="s">&#39;purelib =&#39;</span><span class="p">,</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_path</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s">&#39;purelib&#39;</span><span class="p">,</span> <span class="n">scheme</span><span class="o">=</span><span class="n">scheme</span><span class="p">)</span>
    <span class="k">print</span>
    
</pre></div>
</div>
<p>Using <tt class="xref py py-func docutils literal"><span class="pre">get_path()</span></tt> is equivalent to saving the value of
<tt class="xref py py-func docutils literal"><span class="pre">get_paths()</span></tt> and looking up the individual key in the dictionary.
If you need several paths, <tt class="xref py py-func docutils literal"><span class="pre">get_paths()</span></tt> is more efficient because
it does not recompute all of the paths each time.</p>
<div class="highlight-python"><pre>$ python sysconfig_get_path.py

posix_prefix
============
purelib = /Users/dhellmann/.virtualenvs/pymotw/lib/python2.7/site-packages

posix_user
==========
purelib = /Users/dhellmann/Library/Python/2.7/lib/python2.7/site-packages</pre>
</div>
</div>
<div class="section" id="python-version-and-platform">
<h2>Python Version and Platform<a class="headerlink" href="#python-version-and-platform" title="Permalink to this headline">¶</a></h2>
<p>While <a class="reference internal" href="../sys/index.html#module-sys" title="sys: System-specific configuration"><tt class="xref py py-mod docutils literal"><span class="pre">sys</span></tt></a> includes some basic platform identification (see
<a class="reference internal" href="../sys/interpreter.html#sys-build-time-info"><em>Build-time Version Information</em></a>), it is not specific enough to be used for
installing binary packages because <tt class="docutils literal"><span class="pre">sys.platform</span></tt> does not always
include information about hardware architecture, bit-ness, or other
values that effect the compatibility of binary libraries.  For a more
precise platform specifier, use <tt class="xref py py-func docutils literal"><span class="pre">get_platform()</span></tt>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>

<span class="k">print</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_platform</span><span class="p">()</span>
</pre></div>
</div>
<p>Although this sample output was prepared on an OS X 10.6 system, the
interpreter is compiled for 10.5 compatibility, so that is the version
number included in the platform string.</p>
<div class="highlight-python"><pre>$ python sysconfig_get_platform.py

macosx-10.5-fat3</pre>
</div>
<p>As a convenience, the interpreter version from <tt class="docutils literal"><span class="pre">sys.version_info</span></tt> is
also available through <tt class="xref py py-func docutils literal"><span class="pre">get_python_version()</span></tt> in <a class="reference internal" href="#module-sysconfig" title="sysconfig: Interpreter Compile-time Configuration"><tt class="xref py py-mod docutils literal"><span class="pre">sysconfig</span></tt></a>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">sysconfig</span>
<span class="kn">import</span> <span class="nn">sys</span>

<span class="k">print</span> <span class="s">&#39;sysconfig.get_python_version() =&gt;&#39;</span><span class="p">,</span> <span class="n">sysconfig</span><span class="o">.</span><span class="n">get_python_version</span><span class="p">()</span>
<span class="k">print</span> <span class="s">&#39;sys.version_info =&gt;&#39;</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span>
</pre></div>
</div>
<p><tt class="xref py py-func docutils literal"><span class="pre">get_python_version()</span></tt> returns a string suitable for use when
building a version-specific path.</p>
<div class="highlight-python"><pre>$ python sysconfig_get_python_version.py

sysconfig.get_python_version() =&gt; 2.7
sys.version_info =&gt; sys.version_info(major=2, minor=7, micro=0, releaselevel='final', serial=0)</pre>
</div>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt><a class="reference external" href="http://docs.python.org/library/sysconfig.html">sysconfig</a></dt>
<dd>The standard library documentation for this module.</dd>
<dt><tt class="xref py py-mod docutils literal"><span class="pre">distutils</span></tt></dt>
<dd><a class="reference internal" href="#module-sysconfig" title="sysconfig: Interpreter Compile-time Configuration"><tt class="xref py py-mod docutils literal"><span class="pre">sysconfig</span></tt></a> used to be part of the <tt class="xref py py-mod docutils literal"><span class="pre">distutils</span></tt> package.</dd>
<dt><a class="reference external" href="http://hg.python.org/distutils2/">distutils2</a></dt>
<dd>Updates to <tt class="xref py py-mod docutils literal"><span class="pre">distutils</span></tt>, managed by Tarek Ziadé.</dd>
<dt><a class="reference internal" href="../site/index.html#module-site" title="site: Site-wide configuration"><tt class="xref py py-mod docutils literal"><span class="pre">site</span></tt></a></dt>
<dd>The <a class="reference internal" href="../site/index.html#module-site" title="site: Site-wide configuration"><tt class="xref py py-mod docutils literal"><span class="pre">site</span></tt></a> module describes the paths searched when
importing in more detail.</dd>
<dt><a class="reference internal" href="../os/index.html#module-os" title="os: Portable access to operating system specific features."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a></dt>
<dd>Includes <tt class="docutils literal"><span class="pre">os.name</span></tt>, the name of the current operating system.</dd>
<dt><a class="reference internal" href="../sys/index.html#module-sys" title="sys: System-specific configuration"><tt class="xref py py-mod docutils literal"><span class="pre">sys</span></tt></a></dt>
<dd>Includes other build-time information such as the platform.</dd>
</dl>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <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="../traceback/index.html" title="traceback – Extract, format, and print exceptions and stack traces."
             >next</a> |</li>
        <li class="right" >
          <a href="../sys/imports.html" title="Modules and Imports"
             >previous</a> |</li>
        <li><a href="../contents.html">PyMOTW</a> &raquo;</li>
          <li><a href="../runtime_services.html" >Python Runtime Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright Doug Hellmann.
      Last updated on Oct 24, 2010.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.

    <br/><a href="http://creativecommons.org/licenses/by-nc-sa/3.0/us/" rel="license"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/3.0/us/88x31.png"/></a>
    
    </div>
  </body>
</html>

[top] / python / PyMOTW / docs / sysconfig / index.html

contact | logmethods.com