-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac.html
More file actions
320 lines (299 loc) · 19.9 KB
/
mac.html
File metadata and controls
320 lines (299 loc) · 19.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<!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" lang="zh_TW">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>4. 在麥金塔系統使用Python — Python 3.7.0 說明文件</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/translations.js"></script>
<script type="text/javascript" src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.7.0 說明文件 中搜尋"
href="../_static/opensearch.xml"/>
<link rel="author" title="關於這些文件" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜尋" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="The Python Language Reference" href="../reference/index.html" />
<link rel="prev" title="3. 在 Windows 上使用 Python" href="windows.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.org/3/using/mac.html" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/switchers.js"></script>
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="../reference/index.html" title="The Python Language Reference"
accesskey="N">下一頁</a> |</li>
<li class="right" >
<a href="windows.html" title="3. 在 Windows 上使用 Python"
accesskey="P">上一頁</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">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Setup and Usage</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="using-python-on-a-macintosh">
<span id="using-on-mac"></span><h1>4. 在麥金塔系統使用Python<a class="headerlink" href="#using-python-on-a-macintosh" title="本標題的永久連結">¶</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-odd field"><th class="field-name">Author:</th><td class="field-body">Bob Savage <<a class="reference external" href="mailto:bobsavage%40mac.com">bobsavage<span>@</span>mac<span>.</span>com</a>></td>
</tr>
</tbody>
</table>
<p>Python 執行在麥金塔系統的 Mac OS X 和執行在其他 Unix 平台上原理非常相似,但有一些值得提出的是在 Mac OS X 上增加其他額外的功能例如 IDE 與 套件管理。</p>
<div class="section" id="getting-and-installing-macpython">
<span id="getting-osx"></span><h2>4.1. 取得和安裝MacPython<a class="headerlink" href="#getting-and-installing-macpython" title="本標題的永久連結">¶</a></h2>
<p>Apple 在 Mac OS X 10.8 預設安裝 Python 2.7。但你也可以到 Python website (<a class="reference external" href="https://www.python.org">https://www.python.org</a> )更新至最新的 Python 3。Python 建立在」通用二進位」上,使 Python 能以本地程序的形式運行在使用英特爾微處理器與 PowerPC 麥金塔電腦上。</p>
<p>在安裝後你必須要做幾件事:</p>
<ul class="simple">
<li>A <code class="file docutils literal notranslate"><span class="pre">MacPython</span> <span class="pre">3.6</span></code> folder in your <code class="file docutils literal notranslate"><span class="pre">Applications</span></code> folder. In here
you find IDLE, the development environment that is a standard part of official
Python distributions; PythonLauncher, which handles double-clicking Python
scripts from the Finder; and the 「Build Applet」 tool, which allows you to
package Python scripts as standalone applications on your system.</li>
<li>A framework <code class="file docutils literal notranslate"><span class="pre">/Library/Frameworks/Python.framework</span></code>, which includes the
Python executable and libraries. The installer adds this location to your shell
path. To uninstall MacPython, you can simply remove these three things. A
symlink to the Python executable is placed in /usr/local/bin/.</li>
</ul>
<p>The Apple-provided build of Python is installed in
<code class="file docutils literal notranslate"><span class="pre">/System/Library/Frameworks/Python.framework</span></code> and <code class="file docutils literal notranslate"><span class="pre">/usr/bin/python</span></code>,
respectively. You should never modify or delete these, as they are
Apple-controlled and are used by Apple- or third-party software. Remember that
if you choose to install a newer Python version from python.org, you will have
two different but functional Python installations on your computer, so it will
be important that your paths and usages are consistent with what you want to do.</p>
<p>IDLE includes a help menu that allows you to access Python documentation. If you
are completely new to Python you should start reading the tutorial introduction
in that document.</p>
<p>If you are familiar with Python on other Unix platforms you should read the
section on running Python scripts from the Unix shell.</p>
<div class="section" id="how-to-run-a-python-script">
<h3>4.1.1. 如何執行Python腳本<a class="headerlink" href="#how-to-run-a-python-script" title="本標題的永久連結">¶</a></h3>
<p>Your best way to get started with Python on Mac OS X is through the IDLE
integrated development environment, see section <a class="reference internal" href="#ide"><span class="std std-ref">整合化開發工具</span></a> and use the Help menu
when the IDE is running.</p>
<p>If you want to run Python scripts from the Terminal window command line or from
the Finder you first need an editor to create your script. Mac OS X comes with a
number of standard Unix command line editors, <strong class="program">vim</strong> and
<strong class="program">emacs</strong> among them. If you want a more Mac-like editor,
<strong class="program">BBEdit</strong> or <strong class="program">TextWrangler</strong> from Bare Bones Software (see
<a class="reference external" href="http://www.barebones.com/products/bbedit/index.html">http://www.barebones.com/products/bbedit/index.html</a>) are good choices, as is
<strong class="program">TextMate</strong> (see <a class="reference external" href="https://macromates.com/">https://macromates.com/</a>). Other editors include
<strong class="program">Gvim</strong> (<a class="reference external" href="http://macvim-dev.github.io/macvim/">http://macvim-dev.github.io/macvim/</a>) and <strong class="program">Aquamacs</strong>
(<a class="reference external" href="http://aquamacs.org/">http://aquamacs.org/</a>).</p>
<p>To run your script from the Terminal window you must make sure that
<code class="file docutils literal notranslate"><span class="pre">/usr/local/bin</span></code> is in your shell search path.</p>
<p>從Finder執行你的腳本時,你有兩個選項:</p>
<ul class="simple">
<li>Drag it to <strong class="program">PythonLauncher</strong></li>
<li>Select <strong class="program">PythonLauncher</strong> as the default application to open your
script (or any .py script) through the finder Info window and double-click it.
<strong class="program">PythonLauncher</strong> has various preferences to control how your script is
launched. Option-dragging allows you to change these for one invocation, or use
its Preferences menu to change things globally.</li>
</ul>
</div>
<div class="section" id="running-scripts-with-a-gui">
<span id="osx-gui-scripts"></span><h3>4.1.2. 透過使用者圖形介面執行腳本<a class="headerlink" href="#running-scripts-with-a-gui" title="本標題的永久連結">¶</a></h3>
<p>With older versions of Python, there is one Mac OS X quirk that you need to be
aware of: programs that talk to the Aqua window manager (in other words,
anything that has a GUI) need to be run in a special way. Use <strong class="program">pythonw</strong>
instead of <strong class="program">python</strong> to start such scripts.</p>
<p>With Python 3.6, you can use either <strong class="program">python</strong> or <strong class="program">pythonw</strong>.</p>
</div>
<div class="section" id="configuration">
<h3>4.1.3. 設定<a class="headerlink" href="#configuration" title="本標題的永久連結">¶</a></h3>
<p>Python on OS X honors all standard Unix environment variables such as
<span class="target" id="index-0"></span><a class="reference internal" href="cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a>, but setting these variables for programs started from the
Finder is non-standard as the Finder does not read your <code class="file docutils literal notranslate"><span class="pre">.profile</span></code> or
<code class="file docutils literal notranslate"><span class="pre">.cshrc</span></code> at startup. You need to create a file
<code class="file docutils literal notranslate"><span class="pre">~/.MacOSX/environment.plist</span></code>. See Apple’s Technical Document QA1067 for
details.</p>
<p>For more information on installation Python packages in MacPython, see section
<a class="reference internal" href="#mac-package-manager"><span class="std std-ref">Installing Additional Python Packages</span></a>.</p>
</div>
</div>
<div class="section" id="the-ide">
<span id="ide"></span><h2>4.2. 整合化開發工具<a class="headerlink" href="#the-ide" title="本標題的永久連結">¶</a></h2>
<p>MacPython ships with the standard IDLE development environment. A good
introduction to using IDLE can be found at
<a class="reference external" href="http://www.hashcollision.org/hkn/python/idle_intro/index.html">http://www.hashcollision.org/hkn/python/idle_intro/index.html</a>.</p>
</div>
<div class="section" id="installing-additional-python-packages">
<span id="mac-package-manager"></span><h2>4.3. Installing Additional Python Packages<a class="headerlink" href="#installing-additional-python-packages" title="本標題的永久連結">¶</a></h2>
<p>There are several methods to install additional Python packages:</p>
<ul class="simple">
<li>Packages can be installed via the standard Python distutils mode (<code class="docutils literal notranslate"><span class="pre">python</span>
<span class="pre">setup.py</span> <span class="pre">install</span></code>).</li>
<li>Many packages can also be installed via the <strong class="program">setuptools</strong> extension
or <strong class="program">pip</strong> wrapper, see <a class="reference external" href="https://pip.pypa.io/">https://pip.pypa.io/</a>.</li>
</ul>
</div>
<div class="section" id="gui-programming-on-the-mac">
<h2>4.4. 圖形化使用者介面(GUI) 程式開發於Mac<a class="headerlink" href="#gui-programming-on-the-mac" title="本標題的永久連結">¶</a></h2>
<p>有許多建立圖形化使用者介面(GUI)應用程式選項使用Python於Mac上</p>
<p><em>PyObjC</em> is a Python binding to Apple’s Objective-C/Cocoa framework, which is
the foundation of most modern Mac development. Information on PyObjC is
available from <a class="reference external" href="https://pythonhosted.org/pyobjc/">https://pythonhosted.org/pyobjc/</a>.</p>
<p>The standard Python GUI toolkit is <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a>, based on the cross-platform
Tk toolkit (<a class="reference external" href="https://www.tcl.tk">https://www.tcl.tk</a>). An Aqua-native version of Tk is bundled with OS
X by Apple, and the latest version can be downloaded and installed from
<a class="reference external" href="https://www.activestate.com">https://www.activestate.com</a>; it can also be built from source.</p>
<p><em>wxPython</em> is another popular cross-platform GUI toolkit that runs natively on
Mac OS X. Packages and documentation are available from <a class="reference external" href="https://www.wxpython.org">https://www.wxpython.org</a>.</p>
<p><em>PyQt</em> is another popular cross-platform GUI toolkit that runs natively on Mac
OS X. More information can be found at
<a class="reference external" href="https://riverbankcomputing.com/software/pyqt/intro">https://riverbankcomputing.com/software/pyqt/intro</a>.</p>
</div>
<div class="section" id="distributing-python-applications-on-the-mac">
<h2>4.5. 貢獻Python應用程式於 Mac<a class="headerlink" href="#distributing-python-applications-on-the-mac" title="本標題的永久連結">¶</a></h2>
<p>The 「Build Applet」 tool that is placed in the MacPython 3.6 folder is fine for
packaging small Python scripts on your own machine to run as a standard Mac
application. This tool, however, is not robust enough to distribute Python
applications to other users.</p>
<p>The standard tool for deploying standalone Python applications on the Mac is
<strong class="program">py2app</strong>. More information on installing and using py2app can be found
at <a class="reference external" href="http://undefined.org/python/#py2app">http://undefined.org/python/#py2app</a>.</p>
</div>
<div class="section" id="other-resources">
<h2>4.6. 其他資源<a class="headerlink" href="#other-resources" title="本標題的永久連結">¶</a></h2>
<p>MacPython 郵件清單對於Python使用者和開發者於Mac 上是一個極佳的支援資源</p>
<p><a class="reference external" href="https://www.python.org/community/sigs/current/pythonmac-sig/">https://www.python.org/community/sigs/current/pythonmac-sig/</a></p>
<p>其他好用的資源是MacPython wiki:</p>
<p><a class="reference external" href="https://wiki.python.org/moin/MacPython">https://wiki.python.org/moin/MacPython</a></p>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目錄</a></h3>
<ul>
<li><a class="reference internal" href="#">4. 在麥金塔系統使用Python</a><ul>
<li><a class="reference internal" href="#getting-and-installing-macpython">4.1. 取得和安裝MacPython</a><ul>
<li><a class="reference internal" href="#how-to-run-a-python-script">4.1.1. 如何執行Python腳本</a></li>
<li><a class="reference internal" href="#running-scripts-with-a-gui">4.1.2. 透過使用者圖形介面執行腳本</a></li>
<li><a class="reference internal" href="#configuration">4.1.3. 設定</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-ide">4.2. 整合化開發工具</a></li>
<li><a class="reference internal" href="#installing-additional-python-packages">4.3. Installing Additional Python Packages</a></li>
<li><a class="reference internal" href="#gui-programming-on-the-mac">4.4. 圖形化使用者介面(GUI) 程式開發於Mac</a></li>
<li><a class="reference internal" href="#distributing-python-applications-on-the-mac">4.5. 貢獻Python應用程式於 Mac</a></li>
<li><a class="reference internal" href="#other-resources">4.6. 其他資源</a></li>
</ul>
</li>
</ul>
<h4>上個主題</h4>
<p class="topless"><a href="windows.html"
title="上一章">3. 在 Windows 上使用 Python</a></p>
<h4>下個主題</h4>
<p class="topless"><a href="../reference/index.html"
title="下一章">The Python Language Reference</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/using/mac.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>瀏覽</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模組索引"
>模組</a> |</li>
<li class="right" >
<a href="../reference/index.html" title="The Python Language Reference"
>下一頁</a> |</li>
<li class="right" >
<a href="windows.html" title="3. 在 Windows 上使用 Python"
>上一頁</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">zh_TW</span>
<span class="version_switcher_placeholder">3.7.0</span>
<a href="../index.html">Documentation </a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Setup and Usage</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-2018, 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 8月 22, 2018.
<a href="../bugs.html">Found a bug</a>?
<br />
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.7.
</div>
</body>
</html>