⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 124.html

📁 Python Essential Reference, Second Edition
💻 HTML
字号:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Robots" content="INDEX,NOFOLLOW">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TITLE>Safari | Python Essential Reference, Second Edition -&gt; Compilation of Extensions</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyM.css">
</HEAD>
<BODY bgcolor="white" text="black" link="#990000" vlink="#990000" alink="#990000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<table width="100%" cellpadding=5 cellspacing=0 border=0 class="navtopbg"><tr><td><font size="1"><p class="navtitle"><a href="2.html" class="navtitle">Linux/Unix</a> &gt; <a href="0735710910.html" class="navtitle">Python Essential Reference, Second Edition</a> &gt; <a href="121.html" class="navtitle">B. Extending and Embedding Python</a> &gt; <span class="nonavtitle">Compilation of Extensions</span></p></font></td><td align="right" valign="top" nowrap><font size="1"><a href="main.asp?list" class="safnavoff">See All Titles</a></font></td></tr></table>
<TABLE width=100% bgcolor=white border=0 cellspacing=0 cellpadding=5><TR><TD>
<TABLE border=0 width="100%" cellspacing=0 cellpadding=0><TR><td align=left width="15%" class="headingsubbarbg"><a href="123.html" title="Enabling Optional Modules"><font size="1">&lt;&nbsp;BACK</font></a></td><td align=center width="70%" class="headingsubbarbg"><font size="1"><a href="popanote.asp?pubui=oreilly&bookname=0735710910&snode=124" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="124.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="125.html" title="Converting Data from Python to C"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
<a href="5%2F28%2F2002+9%3A08%3A55+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>155117184014003188065099048180054212144238241179195140058238111161105094192217201128182154</font><a href="read4.asp?bookname=0735710910&snode=124&now=5%2F28%2F2002+9%3A08%3A55+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
<h3>Compilation of Extensions</h3>
<p>Extension modules are usually compiled into shared libraries or DLLs that can be dynamically loaded by the interpreter. The low-level details of this process vary by machine, but the <tT CLAss="monofont">distutils</tt>  module in the Python library can be used to simplify the process. To create an extension module using <TT CLass="monofont">distutils</tT>, follow these steps:</P>

<OL type="1">
<li>

<p>Create a file called <tt class="monofont">setup.py</tt>  that starts with the following code:</p>

<pre>

# setup.py 
from distutils.core import setup, Extension </Pre>
</Li>
<li>

<P>Add some source information about your extension as follows:</p>

<pre>

setup(name="spam", version="1.0", 
      ext_modules=[Extension("spam", ["spam.c", "spamwrapper.c"])]) </Pre>
</lI>
<LI>

<P>To build your extension, type the following:</p>

<pre>

python setup.py build </PRE>
</Li>
</ol>

<p>At this point, a shared library such as <TT CLass="monofont">spammodule.so</tT> (or some variant of this name such as <TT Class="monofont">spammodule.sl</tt>  or <tt class="monofont">spammodule.dll</tt>) will be created in a special 揵uild

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -