-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmac.html
More file actions
287 lines (266 loc) · 22.6 KB
/
Copy pathmac.html
File metadata and controls
287 lines (266 loc) · 22.6 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
<!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="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>4. Macintosh で Python を使う — Python 3.6.5 ドキュメント</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">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '3.6.5',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</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.6.5 ドキュメント 内を検索"
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="Python 言語リファレンス" 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.jp/3/using/mac.html" /><script type="text/javascript">
$(document).ready(function() {
var base = 'https://docs.python.org/3.6/using/mac.html';
$('a.headerlink').each(function() {
var html = '<a href="' + base + $(this).attr('href') +
'" title="原文へのリンク"><small>(原文)</small></a>';
$(this).after(html);
})
});
</script>
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/version_switch.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="総索引"
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="Python 言語リファレンス"
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="version_switcher_placeholder">3.6.5</span>
<a href="../index.html">ドキュメント</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python のセットアップと利用</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. Macintosh で 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">著者:</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>Mac OS X が動作している Macintosh 上の Python は原則的には他の Unix プラットフォーム上の Python と非常によく似ていますが、 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>Mac OS X 10.8 には Apple によって Python 2.7 がプリインストールされています。Python の Web サイト (<a class="reference external" href="https://www.python.org">https://www.python.org</a>) から最新バージョンの Python 3 を取得しインストールすることもできます。新しい Intel の CPU でも古い PPC の CPU でもネイティブに動作する "ユニバーサル・バイナリ" ビルドの最新のものがあります。</p>
<p>インストールを行うといくつかのものが手に入ります:</p>
<ul class="simple">
<li>A <code class="file docutils literal"><span class="pre">MacPython</span> <span class="pre">3.6</span></code> folder in your <code class="file docutils literal"><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>Python 実行ファイルやライブラリを含む <code class="file docutils literal"><span class="pre">/Library/Frameworks/Python.framework</span></code> フレームワーク。インストーラはシェルのパスにこの場所を追加します。 MacPython をアンインストールするには、これら 3 つを削除すればよいだけです。 Python 実行ファイルへのシンボリックリンクは /usr/local/bin/ に置かれています。</li>
</ul>
<p>Apple が提供している Python のビルドは <code class="file docutils literal"><span class="pre">/System/Library/Frameworks/Python.framework</span></code> と <code class="file docutils literal"><span class="pre">/usr/bin/python</span></code> にそれぞれインストールされています。これらは Apple が管理しているものであり Apple やサードパーティのソフトウェアが使用するので、編集したり削除したりしてはいけません。 python.org から新しいバージョンの Python をインストールする場合には、それぞれ正常に動作する 2 つの異なる Python 環境がコンピュータにインストールされるため、意図する方の Python のパスを設定し、使用することが重要です。</p>
<p>IDLE にはヘルプメニューがあり Python のドキュメントにアクセスすることができます。もし Python が全くの初めての場合にはドキュメントのチュートリアルを最初から読み進めることをおすすめします。</p>
<p>もし他の Unix プラットフォームで Python を使い慣れている場合には Unix シェルからの Python スクリプトの実行についての節を読むことをおすすめします。</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>Mac OS X で Python を始める最良の方法は統合開発環境である IDLE を使うことです、 <a class="reference internal" href="#ide"><span class="std std-ref">IDE</span></a> 節を参照し IDE を実行しているときにヘルプメニューを使ってください。</p>
<p>もし Python スクリプトをターミナルのコマンドラインや Finder から実行したい場合は最初にエディタでスクリプトを作る必要があります。 Mac OS X には <strong class="program">vim</strong> や <strong class="program">emacs</strong> などの Unix の標準のラインエディタが備わっています。もしもっと Mac らしいエディタが欲しい場合には、Bare Bones Software (<a class="reference external" href="http://www.barebones.com/products/bbedit/index.html">http://www.barebones.com/products/bbedit/index.html</a> を参照) の <strong class="program">BBEdit</strong> や <strong class="program">TextWrangler</strong> もしくは <strong class="program">TextMate</strong> (<a class="reference external" href="https://macromates.com/">https://macromates.com/</a>) は良い選択候補です。他には <strong class="program">Gvim</strong> (<a class="reference external" href="http://macvim.org">http://macvim.org</a>) や <strong class="program">Aquamacs</strong> (<a class="reference external" href="http://aquamacs.org/">http://aquamacs.org/</a>) などがあります。</p>
<p>ターミナルからスクリプトを実行するには <code class="file docutils literal"><span class="pre">/usr/local/bin</span></code> がシェルのパスに含まれていることを確認してください。</p>
<p>Finder からスクリプトを実行するのには 2 つの方法があります:</p>
<ul class="simple">
<li><strong class="program">PythonLauncher</strong> へドラッグする</li>
<li>Finder の情報ウィンドウから <strong class="program">PythonLauncher</strong> をそのスクリプト (もしくは .py スクリプト全て) を開くデフォルトのアプリケーションとして選び、スクリプトファイルをダブルクリックしてください。 <strong class="program">PythonLauncher</strong> の環境設定にはどのようにスクリプトを実行するかを管理する様々な設定があります。 option キーを押しながらドラッグすることで実行するごとにこれらの設定を変えられますし、環境設定メニューから全ての実行に対して設定変更することもできます。</li>
</ul>
</div>
<div class="section" id="running-scripts-with-a-gui">
<span id="osx-gui-scripts"></span><h3>4.1.2. GUI でスクリプトを実行<a class="headerlink" href="#running-scripts-with-a-gui" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>古いバージョンの Python には、気を付けておかないといけない Mac OS X の癖があります: Aqua ウィンドウマネージャとやりとりをする (別の言い方をすると GUI を持つ) プログラムは特別な方法で実行する必要があります。
そのようなスクリプトを実行するには <strong class="program">python</strong> ではなく <strong class="program">pythonw</strong> を使ってください。</p>
<p>Python 3.6 では、 <strong class="program">python</strong> と <strong class="program">pythonw</strong> のどちらでも使えます。</p>
</div>
<div class="section" id="configuration">
<h3>4.1.3. Configuration<a class="headerlink" href="#configuration" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>OS X 上の Python では <span class="target" id="index-2"></span><a class="reference internal" href="cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONPATH</span></code></a> のような全ての標準の Unix 環境変数が使えますが、Finder からプログラムを起動する場合このような環境変数を設定する方法は非標準であり Finder は起動時に <code class="file docutils literal"><span class="pre">.profile</span></code> や <code class="file docutils literal"><span class="pre">.cshrc</span></code> を読み込みません。 <code class="file docutils literal"><span class="pre">~/.MacOSX/environment.plist</span></code> ファイルを作る必要があります。詳細については Apple の Technical Document QA1067 を参照してください。</p>
<p>MacPython の Python パッケージのインストールについてのさらなる情報は、 <a class="reference internal" href="#mac-package-manager"><span class="std std-ref">追加の Python パッケージのインストール</span></a> 節を参照してください。</p>
</div>
</div>
<div class="section" id="the-ide">
<span id="ide"></span><h2>4.2. IDE<a class="headerlink" href="#the-ide" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>MacPython には標準の IDLE 開発環境が付いてきます。<a class="reference external" href="https://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html">https://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html</a> に IDLE を使うための良い入門があります。</p>
</div>
<div class="section" id="installing-additional-python-packages">
<span id="mac-package-manager"></span><h2>4.3. 追加の Python パッケージのインストール<a class="headerlink" href="#installing-additional-python-packages" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>追加の Python パッケージをインストールする方法がいくつかあります:</p>
<ul class="simple">
<li>パッケージは Python の標準の distutils モードを使ってインストールすることができます (<code class="docutils literal"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></code>)。</li>
<li>多くのパッケージは <strong class="program">setuptools</strong> 拡張や <strong class="program">pip</strong> ラッパーを使ってもインストールできます。 <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. Mac での GUI プログラミング<a class="headerlink" href="#gui-programming-on-the-mac" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>Python で Mac 上の GUI アプリケーションをビルドする方法がいくつかあります。</p>
<p><em>PyObjC</em> は Mac の最新の開発基盤である Apple の Objective-C/Cocoa フレームワークへの Python バインディングです。PyObjC の情報は <a class="reference external" href="https://pythonhosted.org/pyobjc/">https://pythonhosted.org/pyobjc/</a> にあります。</p>
<p>Python 標準の GUI ツールキットは、クロスプラットフォームの Tk ツールキット (<a class="reference external" href="https://www.tcl.tk">https://www.tcl.tk</a>) 上に構築された <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"><span class="pre">tkinter</span></code></a> です。 Tk の Aqua ネイティブバージョンは Apple が OS X にバンドルしており、最新バージョンは <a class="reference external" href="https://www.activestate.com">https://www.activestate.com</a> からダウンロードおよびインストールできます; またソースからビルドすることもできます。</p>
<p><em>wxPython</em> は別の人気のあるクロスプラットフォームの GUI ツールキットで Mac OS X 上でネイティブに動作します。パッケージとドキュメントは <a class="reference external" href="http://www.wxpython.org">http://www.wxpython.org</a> から利用できます。</p>
<p><em>PyQt</em> は別の人気のあるクロスプラットフォームの GUI ツールキットで Mac OS X 上でネイティブに動作します。詳しい情報は <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. Mac 上の Python アプリケーションの配布<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>Mac 上の単独の Python アプリケーションをデプロイする標準のツールは <strong class="program">py2app</strong> です。 py2app のインストールと使用法に関する情報は <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 メーリングリストは Mac での Python ユーザや開発者にとって素晴しいサポートリソースです:</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. Macintosh で 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. GUI でスクリプトを実行</a></li>
<li><a class="reference internal" href="#configuration">4.1.3. Configuration</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-ide">4.2. IDE</a></li>
<li><a class="reference internal" href="#installing-additional-python-packages">4.3. 追加の Python パッケージのインストール</a></li>
<li><a class="reference internal" href="#gui-programming-on-the-mac">4.4. Mac での GUI プログラミング</a></li>
<li><a class="reference internal" href="#distributing-python-applications-on-the-mac">4.5. Mac 上の Python アプリケーションの配布</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="次の章へ">Python 言語リファレンス</a></p>
<div role="note" aria-label="source link">
<h3>このページ</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">バグ報告</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.6/Doc/using/mac.rst"
rel="nofollow">ソースの表示
</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="総索引"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Pythonモジュール索引"
>モジュール</a> |</li>
<li class="right" >
<a href="../reference/index.html" title="Python 言語リファレンス"
>次へ</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="version_switcher_placeholder">3.6.5</span>
<a href="../index.html">ドキュメント</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python のセットアップと利用</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 />
Python Software Foundation は非営利団体です。
<a href="https://www.python.org/psf/donations/">寄付</a>
<br />
最終更新日時: 7月 29, 2018
<a href="../bugs.html">バグを見つけたら</a>?
<br />
このドキュメントは <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.6.5 を使って作成されました。
</div>
</body>
</html>