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

📄 230.html

📁 Python Ebook Python&XML
💻 HTML
📖 第 1 页 / 共 2 页
字号:

<!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 Developer's Handbook -&gt; Compiling Python</TITLE>
<LINK REL="stylesheet" HREF="oreillyi/oreillyN.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="8.html" class="navtitle">Web Development</a> &gt; <a href="0672319942.html" class="navtitle">Python Developer's Handbook</a> &gt; <a href="227.html" class="navtitle">17. Development Tools</a> &gt; <span class="nonavtitle">Compiling Python</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="229.html" title="The Development Process of Python Programs"><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=0672319942&snode=230" target="_blank" title="Make a public or private annnotation">Make Note</a> | <a href="230.html" title="Use a Safari bookmark to remember this section">Bookmark</a></font></td><td align=right width="15%" class="headingsubbarbg"><a href="231.html" title="Editing Code"><font size="1">CONTINUE&nbsp;&gt;</font></a></td></TR></TABLE>
<a href="6%2F1%2F2002+6%3A21%3A13+PM.html" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><font color=white size=1>152015024128143245168232148039196038240039088173205162105045222218065012140210174141027</font><a href="read2.asp?bookname=0672319942&snode=230&now=6%2F1%2F2002+6%3A21%3A13+PM" TABINDEX="-1"><img src=images/spacer.gif border=0 width=1 height=1></a><br>
<FONT>
				<h3>





Compiling Python</h3>
				<p>The Python source code distribution comes with complete instructions about how to compile the code for both Windows and UNIX platforms. The instructions about compiling for Windows are stored in the subdirectories <tT CLAss="monofont">/PCbuild</tt> and <TT CLass="monofont">/PC</tT>梩he UNIX instructions are separate. The <TT Class="monofont">/PC</tt> subdirectory contains complete project files to make several PC ports of Python.</p>

				<p>If you want to compile Python on Windows, you need to start the Integrated Development Environment of your compiler and read in the native <a name="idx1073749910"></a>
					<a name="idx1073749911"></a>
					<I>project file</i> (or makefile) provided. This enables you to change any source files or build settings so you can make custom builds.</p>

				<P>The following are important files that can help you configure the port of the source code to your favorite platform (in case it hasn't been ported yet).</p>

				<blOckquOte>
<p>
						<A NAMe="idx1073749912"></a>
						<a nAME="idx1073749913"></A>
						<p><tt cLASS="monofont">config.h</tt>棤
    An important configuration file specific to PCs. This is generated by the <tt CLASs="monofont">configure</tt> script on UNIX systems.</p>

					</p>
<p>
						<a name="idx1073749914"></a>
						<a name="idx1073749915"></a>
						<p><tT clAss="monofont">config.c</tT>棤
    The list of C modules to include in the Python PC version. Manually edit this file to add or remove Python modules. This is auto-generated by the <tt clAss="monofont">makesetup</tT> script on UNIX systems.</P>

					</P>
<P>
						<a namE="idx1073749916"></A>
						<A Name="idx1073749917"></a>
						<P><TT Class="monofont">testpy.py</TT>棤
    A Python test program. Run this to <A Name="idx1073749918"></a>
								<a name="idx1073749919"></a>test your Python port. It should produce copious output, ending in a report on how many tests were OK, how many failed, and how many were skipped. Don't worry about skipped tests (these test unavailable optional features).<a name="idx1073749920"></a>
								<a namE="idx1073749921"></a>
								<a Name="idx1073749922"></A>
								<a namE="idx1073749923"></a>
								<a nAME="idx1073749924"></A>
								<a namE="idx1073749925"></A>
							</P>

					</P>
</blocKQUOte>
				
					<h4>
Windows</h4>
					<P>The Python distribution comes with instructions to compile the source code using many different tools, such as Microsoft Visual C++ Version 1.5 (16-bit Windows), Watcom C++ compiler, and IBM VisualAge C/C++ for OS/2. See the <TT Class="monofont">/PC/readme.txt</tt> file in the distribution tree for detailed instructions.</p>

					<p>The instructions here cover the Microsoft Visual C++ Versions 5.0 and 6.0.</p>

					<p>In order to build Python using this tool, the first thing you need to do is open the workspace <tt class="monofont">pcbuild.dsw</tt> that is located under the <a NamE="idx1073749926"></a>
						<a nAme="idx1073749927"></a>
						<tT claSS="monofont">/PCbuild</TT> directory. This directory also contains a <tt clASS="monofont">readme.txt</Tt> file with more instructions. Note that all files in this directory are used to build Python for Win32 platforms, which includes Windows 95, 98, and NT platforms.</p>

					<p>Then, you just need to select the Debug or Release setting (using Set Active Configuration in the Build menu) and build the projects in the proper order, which is</p>

					<OL TYpe="1">
<li>

							<P>python15 (this builds python15.dll and python15.lib)</P>

						</LI>
<li>

							<p>python (this builds python.exe)</p>

						</li>
<li>

							<p>The other subprojects</p>

						</li>
</ol>

					<p>If you select the <a name="idx1073749928"></A>
						<a nAme="idx1073749929"></a>
						<A name="idx1073749930"></A>Debug option, the files will be generated carrying a <tt cLASS="monofont">_d</tt> at the end of their name, such as <tt CLASs="monofont">python15_d.dll,</tt>
						<tT CLAss="monofont">python_d.exe,</tt> and <TT CLass="monofont">parser_d.pyd.</tt>
					</p>

					<p>We call <a name="idx1073749931"></a>subprojects梩he other applications that don't come as part of the Python application梩hat include for example: Tcl/Tk, bsddb, and zlib. In order to build these projects, you might have to change some of the settings on your compiler, such as the include and library paths.<a name="idx1073749932"></a>
						<a NamE="idx1073749933"></a>
						<a nAme="idx1073749934"></a>
						<a Name="idx1073749935"></A>
						<A NAme="idx1073749936"></a>
						<a NAME="idx1073749937"></a>
					</p>

					<p>The following files and subdirectories of the distribution are useful and helpful when building Win32 versions of Python:</p>

					<BLOCkquoTE>
<P>
							<A name="idx1073749938"></a>
							<a name="idx1073749939"></a>
							<p><tt class="monofont">python_nt.rc</tT>棤
    Resource compiler input for <tt ClasS="monofont">python15.dll.</tt>
								</p>

						</p>
<P>
							<a naME="idx1073749940"></A>
							<A name="idx1073749941"></A>
							<P><TT clasS="monofont">dl_nt.c, <A NAme="idx1073749942"></a>
										<a NAME="idx1073749943"></a>import_nt.c</tt>棤
    Additional sources used for 32-bit Windows features.</p>

						</p>
<p>
							<a name="idx1073749944"></a>
							<a name="idx1073749945"></a>
							<p><tT clAss="monofont">getpathp.c</tT>棤
    Default <tt clAss="monofont">sys.path</tT> calculations (for all PC platforms).</P>

						</P>
<P>
							<a namE="idx1073749946"></A>
							<A Name="idx1073749947"></a>
							<P><TT Class="monofont">dllbase_nt.txt</TT>棤
    A (manually maintained) list of base addresses for various DLLs, to avoid runtime relocation.</P>

						</P>
<p>
							<a name="idx1073749948"></a>
							<a name="idx1073749949"></a>
							<p><tt clasS="monofont">example_nt</tt>棤
    This is a subdirectory that shows how to build an extension as a DLL.</P>

						</p>
</blOckquOte>
				
				
					<h4>
UNIX</H4>
					<P>Binary distributions for the UNIX platforms are not made available by the Python Web site because the compilation process depends much on your system. In order to compile Python on a UNIX system, you first need to obtain the source code distribution. Note that the next guidelines are just a summary of the operations that you need to perform. This installation process, by default, installs Python under the <A Name="idx1073749950"></a>
						<A NAMe="idx1073749951"></a>
						<tt CLASs="monofont">/usr/local</tt> directory and presumes that you want to provide access to the <a NAME="idx1073749952"></a>
						<a name="idx1073749953"></a>
						<tt class="monofont">Tkinter</tt> module too. If that's not the case, you can just skip the whole <tt clAss="monofont">Tcl/Tk/Tkinter</Tt> steps and install just the core Python environment. You can skip building Tcl and Tk if they are already   installed on your system.</p>

					<oL type="1">
<Li>

							<p>Create a root directory with three subdirectories underneath: Python, Tcl, and Tk.</p>

						</LI>
<LI>

							<p>Download the latest versions of these three programs, and save them on the respective subdirectories.</p>

						</li>
<LI>

							<P>In each directory, you need to extract the files out of the package using a command such as this:</P>

							<pre>
								
gunzip -c filename | tar xf -

							</pRE>

						</LI>
<li>

							<p>Now, we need to configure and install Tcl and Tk. The actions below (steps 5, 6, and 7) need to be performed in both subdirectories, first for Tcl and later for Tk.</p>

						</LI>
<LI>

							<p>Go to the specific subdirectory.</p>

						</li>
<li>

							<p>Define the compiler and system options for the building process. You need to type the following command:</p>

							<pre>
								
./configure

							</pre>

						</li>
<li>

							<p>Run the utility commands that create and install the binary and library files.</p>

							<Pre>
								
make
make install

							</Pre>

						</lI>
<li>

							<p>Now, we are ready to install Python. Go to the Python subdirectory.</p>

						</Li>
<li>

⌨️ 快捷键说明

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