-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows.html
More file actions
877 lines (856 loc) · 93.8 KB
/
Copy pathwindows.html
File metadata and controls
877 lines (856 loc) · 93.8 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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
<!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>3. Windows で 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="4. Macintosh で Python を使う" href="mac.html" />
<link rel="prev" title="2. Unix プラットフォームで Python を使う" href="unix.html" />
<link rel="shortcut icon" type="image/png" href="../_static/py.png" />
<link rel="canonical" href="https://docs.python.jp/3/using/windows.html" /><script type="text/javascript">
$(document).ready(function() {
var base = 'https://docs.python.org/3.6/using/windows.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="mac.html" title="4. Macintosh で Python を使う"
accesskey="N">次へ</a> |</li>
<li class="right" >
<a href="unix.html" title="2. Unix プラットフォームで 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-windows">
<span id="using-on-windows"></span><h1>3. Windows で Python を使う<a class="headerlink" href="#using-python-on-windows" title="このヘッドラインへのパーマリンク">¶</a></h1>
<p>このドキュメントは、 Python を Microsoft Windows で使うときに知っておくべき、 Windows 固有の動作についての概要を伝えることを目的としています。</p>
<div class="section" id="installing-python">
<h2>3.1. Python のインストール<a class="headerlink" href="#installing-python" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>ほとんどの Unix システムとサービスとは違って、Windows には、システムがサポートする Python インストレーションが含まれていません。Python を利用可能にするために、CPython チームは長年の間、すべての <a class="reference external" href="https://www.python.org/download/releases/">リリース</a> で Windows インストーラ (MSI パッケージ) をコンパイルしてきました。単独のユーザで使われるコアインタプリタとライブラリをユーザごとに追加する Python インストレーションを、これらインストーラは主として意図しています。インストーラでは単一マシンのすべてのユーザのためにインストールすることもでき、また、これとは分離されたアプリケーションローカルな配布物の ZIP ファイルも入手可能です。</p>
<div class="section" id="supported-versions">
<h3>3.1.1. サポートされているバージョン<a class="headerlink" href="#supported-versions" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p><span class="target" id="index-48"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0011"><strong>PEP 11</strong></a> で明記しているとおり Python のリリースは、Microsoft が延長サポート期間であるとしている Windows プラットフォームのみをサポートします。
つまり Python 3.6 は Vista とそれより新しい Windows をサポートするということです。
Windows XP サポートが必要な場合は、Python 3.4 をインストールしてください。</p>
</div>
<div class="section" id="installation-steps">
<h3>3.1.2. インストール手順<a class="headerlink" href="#installation-steps" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>ダウンロードできる Python 3.6 のインストーラは 4 つあります。
インタプリタの 32 ビット版、64 ビット版がそれぞれ 2 つずつあります。
<em>WEB インストーラ</em> は最初のダウンロードサイズは小さく、必要なコンポーネントはインストーラ実行時に必要に応じて自動的にダウンロードします。
<em>オフラインインストーラ</em> にはデフォルトインストールに必要なコンポーネントが含まれていて、インターネット接続はオプショナルな機能のためにだけに必要となります。
インストール時にダウンロードを避けるほかの方法については <a class="reference internal" href="#install-layout-option"><span class="std std-ref">ダウンロード不要なインストール</span></a> を参照して下さい。</p>
<p>インストーラを開始すると、2つの選択肢からひとつを選べます:</p>
<img alt="../_images/win_installer.png" src="../_images/win_installer.png" />
<p>"Install Now" を選択した場合:</p>
<ul class="simple">
<li>管理者権限は <em>不要です</em> (ただし C ランタイムライブラリのシステム更新が必要であったり、 <a class="reference internal" href="#launcher"><span class="std std-ref">Windows の Python ランチャ</span></a> をすべてのユーザ向けにインストールする場合は必要です)。</li>
<li>Python はあなたのユーザディレクトリにインストールされます。</li>
<li><a class="reference internal" href="#launcher"><span class="std std-ref">Windows の Python ランチャ</span></a> はこのインストールウィザード最初のページの下部のチェックボックス指定に従ってインストールされます。</li>
<li>標準ライブラリ、テストスイート、ランチャ、pip がインストールされます。</li>
<li>このインストールウィザード最初の下部のチェックボックスをチェックすれば、環境変数 <span class="target" id="index-49"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> にインストールディレクトリが追加されます。</li>
<li>ショートカットはカレントユーザだけに可視になります。</li>
</ul>
<p>"Customize installation" を選択すると、インストール場所、その他オプションやインストール後のアクションの変更などのインストールの有りようを選べます。デバッグシンボルやデバッグバイナリをインストールするならこちらを選択する必要があるでしょう。</p>
<p>すべてのユーザのためのインストールのためには "Customize installation" を選んでください。この場合:</p>
<ul class="simple">
<li>管理者資格か承認が必要かもしれません。</li>
<li>Python は Program Files ディレクトリにインストールされます。</li>
<li><a class="reference internal" href="#launcher"><span class="std std-ref">Windows の Python ランチャ</span></a> は Windows ディレクトリにインストールされます。</li>
<li>オプショナルな機能はインストール中に選択できます。</li>
<li>標準ライブラリをバイトコードにプリコンパイルできます。</li>
<li>そう選択すれば、インストールディレクトリはシステム環境変数 <span class="target" id="index-50"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> に追加されます。</li>
<li>ショートカットがすべてのユーザで利用できるようになります。</li>
</ul>
</div>
<div class="section" id="removing-the-max-path-limitation">
<span id="max-path"></span><h3>3.1.3. MAX_PATH の制限を除去する<a class="headerlink" href="#removing-the-max-path-limitation" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>Windows は歴史的にパスの長さが 260 文字に制限されています。
つまり、これより長いパスは解決できず結果としてエラーになるということです。</p>
<p>Windows の最新版では、この制限は約 32,000 文字まで拡張できます。
管理者が、グループポリシーの "Win32 の長いパスを有効にする (Enable Win32 long paths)" を有効にするか、レジストリ <code class="docutils literal"><span class="pre">HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem@LongPathsEnabled</span></code> の値を <code class="docutils literal"><span class="pre">1</span></code> に設定する必要があります。</p>
<p>この設定によりパスを表すのに string を使っているときに、 <a class="reference internal" href="../library/functions.html#open" title="open"><code class="xref py py-func docutils literal"><span class="pre">open()</span></code></a> 関数や <a class="reference internal" href="../library/os.html#module-os" title="os: Miscellaneous operating system interfaces."><code class="xref py py-mod docutils literal"><span class="pre">os</span></code></a> モジュールやその他の多くのパスに関わる機能が 260 文字よりも長いパスを受け取ったり、返したりできるようになります。
(パスに bytes を使うのは Windows では非推奨で、 bytes を使っているときにはこの機能は利用できません。)</p>
<p>これらのオプションを変更したら、それ以上の設定は必要ありません。</p>
<div class="versionchanged">
<p><span class="versionmodified">バージョン 3.6 で変更: </span>Python で長いパスのサポートが可能になりました。</p>
</div>
</div>
<div class="section" id="installing-without-ui">
<span id="install-quiet-option"></span><h3>3.1.4. インストーラの GUI なしでインストールする<a class="headerlink" href="#installing-without-ui" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>インストーラの GUI で利用できるすべてのオプションは、コマンドラインからも指定できます。これによりユーザとの対話なしで数多くの機器に同じインストールを行うような、スクリプト化されたインストールを行うことができます。ちょっとしたデフォルトの変更のために、GUI を抑制することなしにこれらコマンドラインオプションをセットすることもできます。</p>
<p>完全にインストーラの GUI を隠して Python を静かにインストールするには、 <code class="docutils literal"><span class="pre">/quiet</span></code> オプションを渡してください。対話的に設定するのはスキップしつつも進捗とエラーの表示は行いたいなら、 <code class="docutils literal"><span class="pre">/passive</span></code> オプションを渡してください。 <code class="docutils literal"><span class="pre">/uninstall</span></code> オプションも渡せます。これはプロンプトの表示なしに、即座に Python の削除を開始します。</p>
<p>ほかのすべてのオプションは <code class="docutils literal"><span class="pre">name=value</span></code> の形で渡します。value は大抵 <code class="docutils literal"><span class="pre">0</span></code> で機能を無効化、 <code class="docutils literal"><span class="pre">1</span></code> で機能を有効化、であるとかパスの指定です。利用可能なオプションの完全なリストは以下の通りです。</p>
<table border="1" class="docutils">
<colgroup>
<col width="30%" />
<col width="42%" />
<col width="29%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">名前</th>
<th class="head">説明</th>
<th class="head">デフォルト</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>InstallAllUsers</td>
<td>システムワイドなインストールを実行する。</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>TargetDir</td>
<td>インストール先ディレクトリ。</td>
<td>InstallAllUsers に基いて選択されます。</td>
</tr>
<tr class="row-even"><td>DefaultAllUsersTargetDir</td>
<td>すべてのユーザ向けインストールのためのデフォルトインストール先ディレクトリ。</td>
<td><code class="file docutils literal"><span class="pre">%ProgramFiles%\Python</span> <span class="pre">X.Y</span></code> または <code class="file docutils literal"><span class="pre">%ProgramFiles(x86)%\Python</span> <span class="pre">X.Y</span></code></td>
</tr>
<tr class="row-odd"><td>DefaultJustForMeTargetDir</td>
<td>自分一人用インストールのためのデフォルトインストール先ディレクトリ。</td>
<td><code class="file docutils literal"><span class="pre">%LocalAppData%\Programs\PythonXY</span></code> または <code class="file docutils literal"><span class="pre">%LocalAppData%\Programs\PythonXY-32</span></code></td>
</tr>
<tr class="row-even"><td>DefaultCustomTargetDir</td>
<td>カスタムインストールディレクトリとしてデフォルトで GUI に表示される値。</td>
<td>(空)</td>
</tr>
<tr class="row-odd"><td>AssociateFiles</td>
<td>ランチャもインストールする場合に、ファイルの関連付けを行う。</td>
<td>1</td>
</tr>
<tr class="row-even"><td>CompileAll</td>
<td>すべての <code class="docutils literal"><span class="pre">.py</span></code> ファイルをバイトコンパイルして <code class="docutils literal"><span class="pre">.pyc</span></code> を作る。</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>PrependPath</td>
<td>環境変数 <span class="target" id="index-51"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> にインストールディレクトリとスクリプトディレクトリを、また、環境変数 <span class="target" id="index-52"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATHEXT</span></code> に <code class="docutils literal"><span class="pre">.PY</span></code> を追加する。</td>
<td>0</td>
</tr>
<tr class="row-even"><td>Shortcuts</td>
<td>インストールするインタプリタ、ドキュメント、IDLE へのショートカットを作る。</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>Include_doc</td>
<td>Python マニュアルをインストールする。</td>
<td>1</td>
</tr>
<tr class="row-even"><td>Include_debug</td>
<td>デバッグバイナリをインストールする。</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>Include_dev</td>
<td>開発用のヘッダ・ライブラリをインストールする。</td>
<td>1</td>
</tr>
<tr class="row-even"><td>Include_exe</td>
<td><code class="file docutils literal"><span class="pre">python.exe</span></code> とその関連ファイルをインストールする。</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>Include_launcher</td>
<td><a class="reference internal" href="#launcher"><span class="std std-ref">Windows の Python ランチャ</span></a> をインストールする。</td>
<td>1</td>
</tr>
<tr class="row-even"><td>InstallLauncherAllUsers</td>
<td><a class="reference internal" href="#launcher"><span class="std std-ref">Windows の Python ランチャ</span></a> をすべてのユーザにインストールする。</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>Include_lib</td>
<td>標準ライブラリと拡張モジュールをインストールする。</td>
<td>1</td>
</tr>
<tr class="row-even"><td>Include_pip</td>
<td>バンドル版の pip と setuptools をインストールする。</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>Include_symbols</td>
<td>デバッグシンボル (<cite>*</cite>.pdb) をインストールする。</td>
<td>0</td>
</tr>
<tr class="row-even"><td>Include_tcltk</td>
<td>Tcl/Tk サポートと IDLE をインストールする。</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>Include_test</td>
<td>標準ライブラリのテストスイートをインストールする。</td>
<td>1</td>
</tr>
<tr class="row-even"><td>Include_tools</td>
<td>ユーティリティスクリプトをインストールする。</td>
<td>1</td>
</tr>
<tr class="row-odd"><td>LauncherOnly</td>
<td>ランチャのみをインストールする。これは他のほとんどのオプションを上書きします。</td>
<td>0</td>
</tr>
<tr class="row-even"><td>SimpleInstall</td>
<td>最大限のインストーラ GUI を無効にする。</td>
<td>0</td>
</tr>
<tr class="row-odd"><td>SimpleInstallDescription</td>
<td>単純化されたインストーラ GUI を使う際に表示するカスタムメッセージ。</td>
<td>(空)</td>
</tr>
</tbody>
</table>
<p>例えばデフォルトでシステムワイドな Python インストレーションを静かに行うには、以下コマンドを使えます (コマンドプロンプトより):</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>python-3.6.0.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
</pre></div>
</div>
<p>テストスイートなしの Python のパーソナルなコピーのインストールをユーザに簡単に行わせるには、以下コマンドのショートカットを作れば良いです。これはインストーラの最初のページを単純化して表示し、また、カスタマイズできないようにします:</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>python-3.6.0.exe InstallAllUsers=0 Include_launcher=0 Include_test=0
SimpleInstall=1 SimpleInstallDescription="Just for me, no test suite."
</pre></div>
</div>
<p>(ランチャのインストールを省略するとファイルの関連付けも省略されるので、これはランチャインストールを含めたシステムワイドなインストールをした場合のユーザごとインストールに限った場合のお勧めです。)</p>
<p>The options listed above can also be provided in a file named <code class="docutils literal"><span class="pre">unattend.xml</span></code>
alongside the executable. This file specifies a list of options and values.
When a value is provided as an attribute, it will be converted to a number if
possible. Values provided as element text are always left as strings. This
example file sets the same options and the previous example:</p>
<div class="highlight-xml"><div class="highlight"><pre><span></span><span class="nt"><Options></span>
<span class="nt"><Option</span> <span class="na">Name=</span><span class="s">"InstallAllUsers"</span> <span class="na">Value=</span><span class="s">"no"</span> <span class="nt">/></span>
<span class="nt"><Option</span> <span class="na">Name=</span><span class="s">"Include_launcher"</span> <span class="na">Value=</span><span class="s">"0"</span> <span class="nt">/></span>
<span class="nt"><Option</span> <span class="na">Name=</span><span class="s">"Include_test"</span> <span class="na">Value=</span><span class="s">"no"</span> <span class="nt">/></span>
<span class="nt"><Option</span> <span class="na">Name=</span><span class="s">"SimpleInstall"</span> <span class="na">Value=</span><span class="s">"yes"</span> <span class="nt">/></span>
<span class="nt"><Option</span> <span class="na">Name=</span><span class="s">"SimpleInstallDescription"</span><span class="nt">></span>Just for me, no test suite<span class="nt"></Option></span>
<span class="nt"></Options></span>
</pre></div>
</div>
</div>
<div class="section" id="installing-without-downloading">
<span id="install-layout-option"></span><h3>3.1.5. ダウンロード不要なインストール<a class="headerlink" href="#installing-without-downloading" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>Python のいくつかの機能は最初にダウンロードしたインストーラには含まれていないため、それらの機能をインストールしようと選択するとインターネット接続が必要になります。
インターネット接続が必要にならないように、全てのコンポーネントをすぐにできる限りダウンロードして、完全な <em>配置構成 (layout)</em> を作成し、どんな機能が選択されたかに関わらず、それ以上インターネット接続を必要がないようにします。
この方法のダウンロードサイズは必要以上に大きくなるかもしれませんが、たくさんの回数インストールしようとする場合には、ローカルにキャッシュされたコピーを持つことはとても有用です。</p>
<p>コマンドプロンプトから以下のコマンドを実行して、必要なファイルをできる限り全てダウンロードします。
<code class="docutils literal"><span class="pre">python-3.6.0.exe</span></code> 部分は実際のインストーラの名前に置き換え、同名のファイルどうしの衝突が起こらないように、個別のディレクトリ内に配置構成を作るのを忘れないようにしてください。</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>python-3.6.0.exe /layout [optional target directory]
</pre></div>
</div>
<p>進捗表示を隠すのに <code class="docutils literal"><span class="pre">/quiet</span></code> オプションを指定することもできます。</p>
</div>
<div class="section" id="modifying-an-install">
<h3>3.1.6. インストール後の変更<a class="headerlink" href="#modifying-an-install" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>いったん Python がインストールされたら、Windows のシステム機能の「プログラムと機能」ツールから機能の追加や削除ができます。Python のエントリを選択して「アンインストールと変更」を選ぶことで、インストーラをメンテナンスモードで開きます。</p>
<p>インストーラ GUI で "Modify" を選ぶと、チェックボックスの選択を変えることで機能の追加削除ができます - チェックボックスの選択を変えなければ、何かがインストールされたり削除されたりはしません。いくつかのオプションはこのモードでは変更することはできません。インストールディレクトリなどです。それらを変えたいのであれば、完全に削除してから再インストールする必要があります。</p>
<p>"Repair" では、現在の設定で本来インストールされるべきすべてのファイルを検証し、削除されていたり更新されていたりするファイルを修正します。</p>
<p>"Uninstall" は Python を完全に削除します。「プログラムと機能」内の自身のエントリを持つ <a class="reference internal" href="#launcher"><span class="std std-ref">Windows の Python ランチャ</span></a> の例外が起こります。</p>
</div>
<div class="section" id="other-platforms">
<h3>3.1.7. ほかのプラットフォーム<a class="headerlink" href="#other-platforms" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>Python の継続的な開発の中で、過去にサポートされていた幾つかのプラットフォームが (ユーザーや開発者の不足のために) サポートされなくなっています。すべてのサポートされないプラットフォームについての詳細は <span class="target" id="index-53"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0011"><strong>PEP 11</strong></a> をチェックしてください。</p>
<ul class="simple">
<li><a class="reference external" href="http://pythonce.sourceforge.net/">Windows CE</a> は今でもサポートされています。</li>
<li><a class="reference external" href="https://cygwin.com/">Cygwin</a> インストーラも Python インタープリタのインストールを提供しています。(cf. <a class="reference external" href="ftp://ftp.uni-erlangen.de/pub/pc/gnuwin32/cygwin/mirrors/cygnus/release/python">Cygwin package source</a>, <a class="reference external" href="http://www.tishler.net/jason/software/python/">Maintainer releases</a>)</li>
</ul>
<p>コンパイル済みインストーラが提供されているプラットフォームについての詳細な情報は <a class="reference external" href="https://www.python.org/downloads/windows/">Python for Windows</a> を参照してください。</p>
<div class="admonition seealso">
<p class="first admonition-title">参考</p>
<dl class="last docutils">
<dt><a class="reference external" href="http://dooling.com/index.php/2006/03/14/python-on-xp-7-minutes-to-hello-world/">Python on XP</a></dt>
<dd>"7 Minutes to "Hello World!""
by Richard Dooling, 2006</dd>
<dt><a class="reference external" href="http://www.diveintopython.net/installing_python/windows.html">Installing on Windows</a></dt>
<dd>in "<a class="reference external" href="http://www.diveintopython.net/">Dive into Python: Python from novice to pro</a>"
by Mark Pilgrim, 2004,
ISBN 1-59059-356-1</dd>
<dt><a class="reference external" href="http://python.swaroopch.com/installation.html#installation-on-windows">For Windows users</a></dt>
<dd>in "Installing Python"
in "<a class="reference external" href="http://python.swaroopch.com/">A Byte of Python</a>"
by Swaroop C H, 2003</dd>
</dl>
</div>
</div>
</div>
<div class="section" id="alternative-bundles">
<h2>3.2. 別のバンドル<a class="headerlink" href="#alternative-bundles" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>標準の CPython の配布物の他に、追加の機能を持っている修正されたパッケージがあります。以下は人気のあるバージョンとそのキーとなる機能です:</p>
<dl class="docutils">
<dt><a class="reference external" href="https://www.activestate.com/activepython/">ActivePython</a></dt>
<dd>マルチプラットフォーム互換のインストーラー、ドキュメント、 PyWin32</dd>
<dt><a class="reference external" href="https://www.continuum.io/downloads/">Anaconda</a></dt>
<dd>人気のある (numpy, scipy や pandas のような) 科学系モジュールと、パッケージマネージャ <code class="docutils literal"><span class="pre">conda</span></code> 。</dd>
<dt><a class="reference external" href="https://www.enthought.com/products/canopy/">Canopy</a></dt>
<dd>「包括的な Python 解析環境 (comprehensive Python analysis environment)」で、エディタとほかの開発ツールを含みます。</dd>
<dt><a class="reference external" href="https://winpython.github.io/">WinPython</a></dt>
<dd>ビルド済みの科学系パッケージと、パッケージのビルドのためのツールを含む、Windows 固有のディストリビューション。</dd>
</dl>
<p>これらパッケージは Python や他のライブラリの最新バージョンが含まれるとは限りませんし、コア Python チームはこれらを保守もしませんしサポートもしませんのでご理解ください。</p>
</div>
<div class="section" id="configuring-python">
<h2>3.3. Python を構成する<a class="headerlink" href="#configuring-python" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>コマンドプロンプトより便利に Python を実行するために、Windows のデフォルトの環境変数をいくつか変えたいと思うかもしれません。インストーラは <span class="target" id="index-54"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> と <span class="target" id="index-55"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATHEXT</span></code> 変数を構成させるオプションを提供してはいますが、これは単独のシステムワイドなインストレーションの場合にだけ頼りになるものです。もしもあなたが定常的に複数バージョンの Python を使うのであれば、 <a class="reference internal" href="#launcher"><span class="std std-ref">Windows の Python ランチャ</span></a> の利用を検討してください。</p>
<div class="section" id="excursus-setting-environment-variables">
<span id="setting-envvars"></span><h3>3.3.1. 補足: 環境変数の設定<a class="headerlink" href="#excursus-setting-environment-variables" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>Windows では、環境変数を恒久的にユーザレベルとシステムレベルの両方で設定でき、あるいはコマンドプロンプトから一時的にも設定できます。</p>
<p>To temporarily set environment variables, open Command Prompt and use the
<strong class="command">set</strong> command:</p>
<div class="highlight-doscon"><div class="highlight"><pre><span></span><span class="gp">C:\></span><span class="k">set</span> <span class="nv">PATH</span><span class="p">=</span>C:\Program Files\Python 3.6;<span class="nv">%PATH%</span>
<span class="gp">C:\></span><span class="k">set</span> <span class="nv">PYTHONPATH</span><span class="p">=</span><span class="nv">%PYTHONPATH%</span>;C:\My_python_lib
<span class="gp">C:\></span>python
</pre></div>
</div>
<p>これらの変更は、以降に実行される同じコンソール内で実行される任意のコマンドに適用され、また、そのコンソールから開始するすべてのアプリケーションに引き継がれます。</p>
<p>パーセント記号で変数名を囲んだものは既存の変数の値で展開されるので、新しい値を最初にも最後にも追加することができます。 <strong class="program">python.exe</strong> が入っているディレクトリを <span class="target" id="index-56"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> に追加することは、Python の適切なバージョンが起動するように保証するための一般的な方法です。</p>
<p>デフォルトの環境変数を恒久的に変更するには、「スタート」をクリックして検索ボックスで「環境変数を編集」を検索するか、(コンピュータのプロパティなどから) <span class="guilabel">システムの詳細設定</span> を開いて <span class="guilabel">環境変数の設定</span> ボタンをクリックしてください。これで立ち上がるダイアログで、ユーザ環境変数とシステム環境変数を追加したり修正したりできます。システム変数を変更するにはあなたのマシンへの制限のないアクセス (つまり管理者権限) が必要です。</p>
<div class="admonition note">
<p class="first admonition-title">注釈</p>
<p>Windows はシステム変数の <em>後ろに</em> ユーザ変数を結合します。この振る舞いにより <span class="target" id="index-57"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> の修正時に期待とは異なる結果になることがあります。</p>
<p class="last"><span class="target" id="index-58"></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> 変数は Python 2 と Python 3 のすべてのバージョンで使われるので、インストールされているすべての Python バージョンで互換なコードだけを使うのでない限り、この環境変数は恒久的な設定をすべきではありません。</p>
</div>
<div class="admonition seealso">
<p class="first admonition-title">参考</p>
<dl class="last docutils">
<dt><a class="reference external" href="https://support.microsoft.com/kb/100843">https://support.microsoft.com/kb/100843</a></dt>
<dd>Windows NT の環境変数</dd>
<dt><a class="reference external" href="https://technet.microsoft.com/en-us/library/cc754250.aspx">https://technet.microsoft.com/en-us/library/cc754250.aspx</a></dt>
<dd>一時的に環境変数を変更するための SET コマンドについて。</dd>
<dt><a class="reference external" href="https://technet.microsoft.com/en-us/library/cc755104.aspx">https://technet.microsoft.com/en-us/library/cc755104.aspx</a></dt>
<dd>恒久的に環境変数を変更するための SETX コマンドについて。</dd>
<dt><a class="reference external" href="https://support.microsoft.com/kb/310519">https://support.microsoft.com/kb/310519</a></dt>
<dd>Windows XP での環境変数の管理方法</dd>
<dt><a class="reference external" href="https://www.chem.gla.ac.uk/~louis/software/faq/q1.html">https://www.chem.gla.ac.uk/~louis/software/faq/q1.html</a></dt>
<dd>Louis J. Farrugia による、環境変数の設定についての説明。</dd>
</dl>
</div>
</div>
<div class="section" id="finding-the-python-executable">
<span id="windows-path-mod"></span><h3>3.3.2. Python 実行ファイルを見つける<a class="headerlink" href="#finding-the-python-executable" title="このヘッドラインへのパーマリンク">¶</a></h3>
<div class="versionchanged">
<p><span class="versionmodified">バージョン 3.5 で変更.</span></p>
</div>
<p>自動的に作成される Python インタープリタのスタートメニュー項目を使うだけでなく、Python をコマンドプロンプトから起動したいと思うかもしれません。
インストーラにはそのための設定を行うオプションがあります。</p>
<p>インストーラの最初のページに "Add Python to PATH" というラベルのオプションがあり、これを選択するとインストーラはインストール場所を環境変数 <span class="target" id="index-59"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> に追加します。
<code class="file docutils literal"><span class="pre">Scripts\</span></code> フォルダの場所も追加されます。
これによりコマンドプロンプトから <strong class="command">python</strong> とタイプしてインタプリタを起動したり、 <strong class="command">pip</strong> とタイプしてパッケージインストーラを起動したりできます。
コマンドラインからの起動なので、スクリプトをコマンドライン引数付きで起動することもできます。
<a class="reference internal" href="cmdline.html#using-on-cmdline"><span class="std std-ref">コマンドライン</span></a> の文章を参照して下さい。</p>
<p>インストール時にこのオプションを有効にしていなかったとしても、インストーラを再度実行して「Modify」を選んで、それを有効にし直せます。あるいはそうせずとも、 <span class="target" id="index-60"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> 変数は手動で修正できます。 <a class="reference internal" href="#setting-envvars"><span class="std std-ref">補足: 環境変数の設定</span></a> を参照してください。環境変数 <span class="target" id="index-61"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> には Python インストールディレクトリを含む必要があります。ほかのエントリとはセミコロンで区切って繋いでください。これの実例は以下のようになります (以下最初の 2 つのエントリは既に存在しているものと仮定しています):</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Python 3.6
</pre></div>
</div>
</div>
</div>
<div class="section" id="python-launcher-for-windows">
<span id="launcher"></span><h2>3.4. Windows の Python ランチャ<a class="headerlink" href="#python-launcher-for-windows" title="このヘッドラインへのパーマリンク">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified">バージョン 3.3 で追加.</span></p>
</div>
<p>Windows の Python ランチャは、異なる Python のバージョンの位置の特定と実行を助けるユーティリティです。スクリプト (またはコマンドライン) で特定の Python のバージョンの設定を与えられると、位置を特定し、そのバージョンを実行します。</p>
<p>環境変数 <span class="target" id="index-62"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> による方法と違って、このランチャは Python の一番適切なバージョンを、正しく選択します。このランチャはシステムワイドなものよりもユーザごとのインストレーションの方を優先し、また、新しくインストールされた順よりも言語のバージョンを優先します。</p>
<div class="section" id="getting-started">
<h3>3.4.1. 最初に<a class="headerlink" href="#getting-started" title="このヘッドラインへのパーマリンク">¶</a></h3>
<div class="section" id="from-the-command-line">
<h4>3.4.1.1. コマンドラインから起動する<a class="headerlink" href="#from-the-command-line" title="このヘッドラインへのパーマリンク">¶</a></h4>
<div class="versionchanged">
<p><span class="versionmodified">バージョン 3.6 で変更.</span></p>
</div>
<p>Python 3.3 とそれ以降のシステムワイドなインストレーションでは、ランチャがあなたの <span class="target" id="index-63"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> に追加されます。ランチャは、入手可能なあらゆる Python のバージョンに互換であるため、実際にどのバージョンの Python がインストールされているのかは重要ではありません。ランチャが使えるかを確認するには以下コマンドをコマンドプロンプトより実行してください:</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>py
</pre></div>
</div>
<p>インストールされている最新バージョンの Python が起動するはずです。
通常どおりに終了することもできますし、追加のコマンドライン引数を指定して直接 Python に渡すこともできます。</p>
<p>複数のバージョンの Python (たとえば 2.7 と 3.6) がインストールされている場合は、Python 3.6 が起動することになります。Python 2.7 を起動したいなら、次のコマンドを実行してみてください:</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>py -2.7
</pre></div>
</div>
<p>インストールしてある Python 2.x の最新バージョンを起動したい場合は、次のコマンドを実行してみてください:</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>py -2
</pre></div>
</div>
<p>最新バージョンの Python 2.x が起動するはずです。</p>
<p>以下のようなエラーが出るようであれば、ランチャはインストールされていません:</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>'py' is not recognized as an internal or external command,
operable program or batch file.
</pre></div>
</div>
<p>ユーザごとの Python インストレーションでは、インストール時にオプションで指定しない限り、ランチャは <span class="target" id="index-64"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> に追加されません。</p>
</div>
<div class="section" id="virtual-environments">
<h4>3.4.1.2. 仮想環境 (Virtual environments)<a class="headerlink" href="#virtual-environments" title="このヘッドラインへのパーマリンク">¶</a></h4>
<div class="versionadded">
<p><span class="versionmodified">バージョン 3.5 で追加.</span></p>
</div>
<p>(標準ライブラリの <a class="reference internal" href="../library/venv.html#module-venv" title="venv: Creation of virtual environments."><code class="xref py py-mod docutils literal"><span class="pre">venv</span></code></a> モジュールか外部ツール <code class="docutils literal"><span class="pre">virtualenv</span></code> で作った) 仮想環境がアクティブな状態で Python の明示的なバージョンを指定せずにランチャを起動すると、ランチャはグローバルなインタプリタではなくその仮想環境のものを実行します。グローバルなほうのインタプリタを実行するには、仮想環境の動作を停止するか、または明示的にグローバルな Python バージョンを指定してください。</p>
</div>
<div class="section" id="from-a-script">
<h4>3.4.1.3. スクリプトから起動する<a class="headerlink" href="#from-a-script" title="このヘッドラインへのパーマリンク">¶</a></h4>
<p>テスト用の Python スクリプトを作成しましょう。<code class="docutils literal"><span class="pre">hello.py</span></code> という名前で以下の内容のファイルを作成してください</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="ch">#! python</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"hello from Python </span><span class="si">%s</span><span class="se">\n</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">version</span><span class="p">,))</span>
</pre></div>
</div>
<p>hello.py が存在するディレクトリで、下記コマンドを実行してください:</p>
<div class="highlight-none"><div class="highlight"><pre><span></span>py hello.py
</pre></div>
</div>
<p>インストールされている最新の Python 2.x のバージョン番号が表示されるはずです。では、1行目を以下のように変更してみてください:</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="ch">#! python3</span>
</pre></div>
</div>
<p>コマンドを再実行すると、今度は最新の Python 3.x の情報が表示されるはずです。これまでのコマンドラインの例と同様に、より細かいバージョン修飾子を指定することもできます。Python 2.6 がインストールされている場合、最初の行を <code class="docutils literal"><span class="pre">#!</span> <span class="pre">python2.6</span></code> に変更すると、2.6 のバージョン情報が表示されるはずです。</p>
<p>コマンドからの呼び出しとは異なり、後ろに何もつかない "python" はインストールされている Python2.x の最新バージョンを利用することに注意してください。これは後方互換性と、 <code class="docutils literal"><span class="pre">python</span></code> が一般的に Python 2 を指すUnix との互換性のためです。</p>
</div>
<div class="section" id="from-file-associations">
<h4>3.4.1.4. ファイルの関連付けから起動する<a class="headerlink" href="#from-file-associations" title="このヘッドラインへのパーマリンク">¶</a></h4>
<p>インストール時に、ランチャは Python ファイル (すなわち <code class="docutils literal"><span class="pre">.py</span></code>, <code class="docutils literal"><span class="pre">.pyw</span></code>, <code class="docutils literal"><span class="pre">.pyc</span></code> ファイル) に関連付けられたはずです。そのため、これらのファイルを Windows のエクスプローラーでダブルクリックした際はランチャが使われ、上で述べたのと同じ機能を使ってスクリプトが使われるべきバージョンを指定できるようになります。</p>
<p>このことによる重要な利点は、単一のランチャが先頭行の内容によって複数の Python バージョンを同時にサポートできることです。</p>
</div>
</div>
<div class="section" id="shebang-lines">
<h3>3.4.2. シェバン (shebang) 行<a class="headerlink" href="#shebang-lines" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>If the first line of a script file starts with <code class="docutils literal"><span class="pre">#!</span></code>, it is known as a
"shebang" line. Linux and other Unix like operating systems have native
support for such lines and they are commonly used on such systems to indicate
how a script should be executed. This launcher allows the same facilities to
be used with Python scripts on Windows and the examples above demonstrate their
use.</p>
<p>Python スクリプトのシェバン行を Unix-Windows 間で移植可能にするため、このランチャは、どのインタプリタが使われるかを指定するための大量の '仮想' コマンドをサポートしています。サポートされる仮想コマンドには以下のものがあります:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">/usr/bin/env</span> <span class="pre">python</span></code></li>
<li><code class="docutils literal"><span class="pre">/usr/bin/python</span></code></li>
<li><code class="docutils literal"><span class="pre">/usr/local/bin/python</span></code></li>
<li><code class="docutils literal"><span class="pre">python</span></code></li>
</ul>
<p>具体的に、もしスクリプトの1行目が</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span><span class="ch">#! /usr/bin/python</span>
</pre></div>
</div>
<p>で始まっていたら、デフォルトの Python の位置が特定され、使用されます。多くの Unix 上で動作する Python スクリプトにはすでにこの行が存在する傾向がありますので、ランチャによりそれらのスクリプトを修正なしで使うことができるはずです。あなたが新しいスクリプトを Windows 上で書いていて、Unix 上でも有用であってほしいと思うなら、シェバン行のうち <code class="docutils literal"><span class="pre">/usr</span></code> で始まるものを使用すべきです。</p>
<p>上記の仮想コマンドのいずれでも、明示的にバージョンを指定できます (メジャーバージョンだけでも、メジャー・マイナーバージョン両方でも) - 例えば <code class="docutils literal"><span class="pre">/usr/bin/python2.7</span></code> のように - これによりその特定のバージョンが特定されて使われます。</p>
<p><code class="docutils literal"><span class="pre">/usr/bin/env</span></code> 形式のシェバン行にはもう一つ更に特別な特性があります。インストールされている Python を探す前に、この形式は Python 実行ファイルを <span class="target" id="index-65"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> から検索します。これは Unix の <code class="docutils literal"><span class="pre">env</span></code> プログラムに対応する振る舞いで、これも <span class="target" id="index-66"></span><code class="xref std std-envvar docutils literal"><span class="pre">PATH</span></code> からの検索をするものです。</p>
</div>
<div class="section" id="arguments-in-shebang-lines">
<h3>3.4.3. シェバン行の引数<a class="headerlink" href="#arguments-in-shebang-lines" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>シェバン行では Python インタプリタに渡される追加の引数を指定することもできます。たとえば、シェバン行に以下のように書かれているとしましょう:</p>
<div class="highlight-sh"><div class="highlight"><pre><span></span><span class="ch">#! /usr/bin/python -v</span>
</pre></div>
</div>
<p>この場合、Python は <code class="docutils literal"><span class="pre">-v</span></code> オプション付きで起動するでしょう</p>
</div>
<div class="section" id="customization">
<h3>3.4.4. カスタマイズ<a class="headerlink" href="#customization" title="このヘッドラインへのパーマリンク">¶</a></h3>
<div class="section" id="customization-via-ini-files">
<h4>3.4.4.1. INI ファイルによるカスタマイズ<a class="headerlink" href="#customization-via-ini-files" title="このヘッドラインへのパーマリンク">¶</a></h4>
<p>ランチャは2つの .ini ファイルを探しに行きます。具体的には、現在のユーザーの "application data" ディレクトリ (Windows の関数 SHGetFolderPath に CSIDL_LOCAL_APPDATA を与えて呼ぶと返ってくるディレクトリ) の <code class="docutils literal"><span class="pre">py.ini</span></code> と、ランチャと同じディレクトリにある <code class="docutils literal"><span class="pre">py.ini</span></code> です。'コンソール' 版のランチャ (つまり py.exe) と 'Windows' 版のランチャ (つまり pyw.exe) は同一の .ini ファイルを使用します。</p>
<p>"application data" ディレクトリで指定された設定は、実行ファイルの隣にあるものより優先されます。そのため、ランチャの隣にある .ini ファイルへの書き込みアクセスができないユーザは、グローバルな .ini ファイル内のコマンドを上書き (override) することができます</p>
</div>
<div class="section" id="customizing-default-python-versions">
<h4>3.4.4.2. デフォルトのPythonバージョンのカスタマイズ<a class="headerlink" href="#customizing-default-python-versions" title="このヘッドラインへのパーマリンク">¶</a></h4>
<p>どのバージョンの Python をコマンドで使用するかを定めるため、バージョン修飾子がコマンドに含められることがあります。バージョン修飾子はメジャーバージョン番号で始まり、オプションのピリオド ('.') とマイナーバージョン指定子がそれに続きます。もしマイナー修飾子が指定されれば、オプションでさらに "-32" を続けて、そのバージョンの 32-bit の実装が使われることを示すことができます。</p>
<p>たとえば、<code class="docutils literal"><span class="pre">#!python</span></code> というシェバン行はバージョン修飾子を含みませんが、<code class="docutils literal"><span class="pre">#!python3</span></code> はメジャーバージョンを指定するバージョン修飾子を含みます。</p>
<p>コマンドにバージョン修飾子が見つからない場合、環境変数 <code class="docutils literal"><span class="pre">PY_PYTHON</span></code> を設定してデフォルトバージョン修飾子を指定することができます。デフォルト値は "2" になっています。この値は、単にメジャーバージョン (例えば "2") にすることも、major.minor 修飾子 (例えば "2.6") にすることも、さらには major.minor-32 にすることもできます。</p>
<p>マイナーバージョン修飾子が見つからない場合、環境変数 <code class="docutils literal"><span class="pre">PY_PYTHON{major}</span></code> (ここで <code class="docutils literal"><span class="pre">{major}</span></code> は、上記で決定された現在のメジャーバージョン修飾子) を設定して完全なバージョンを指定することができます。そういったオプションが見つからなければ、ランチャはインストール済みの Python バージョンを列挙して、見つかったそのメジャーバージョン向けマイナーリリースのうち最新のものを使用します。保証されているわけではありませんが、通常はそのメジャーバージョン系で最も後にインストールしたバージョンになります。</p>
<p>64-bit Windows で、同一の (major.minor) Python バージョンの 32-bit と 64-bit の両方の実装がインストールされていた場合、64-bit バージョンのほうが常に優先されます。これはランチャが 32-bit と 64-bit のどちらでも言えることで、32-bit のランチャは、指定されたバージョンが使用可能であれば、64-bit の Python を優先して実行します。これは、どのバージョンが PC にインストールされているかのみでランチャの挙動を予見でき、それらがインストールされた順番に関係なくなる (つまり最後にインストールされた Python とランチャが 32-bit か 64-bit かを知らなくともよい) ようにするためです。上に記したとおり、オプションの "-32" サフィックスでこの挙動を変更できます。</p>
<p>例:</p>
<ul class="simple">
<li>関連するオプションが設定されていない場合、<code class="docutils literal"><span class="pre">python</span></code> および <code class="docutils literal"><span class="pre">python2</span></code> コマンドはインストールされている最新の Python 2.x バージョンを使用し、<code class="docutils literal"><span class="pre">python3</span></code> コマンドはインストールされている最新の Python 3.x を使用します。</li>
<li><code class="docutils literal"><span class="pre">python3.1</span></code> および <code class="docutils literal"><span class="pre">python2.7</span></code> コマンドは、バージョンが完全に指定されているため、全くオプションを参照しません。</li>
<li><code class="docutils literal"><span class="pre">PY_PYTHON=3</span></code> の場合、<code class="docutils literal"><span class="pre">python</span></code> および <code class="docutils literal"><span class="pre">python3</span></code> コマンドはともにインストールされている最新の Python 3 を使用します。</li>
<li><code class="docutils literal"><span class="pre">PY_PYTHON=3.1-32</span></code> の場合、<code class="docutils literal"><span class="pre">python</span></code> コマンドは 32-bit 版の 3.1 を使用しますが、<code class="docutils literal"><span class="pre">python3</span></code> コマンドはインストールされている最新の Python を使用します (メジャーバージョンが指定されているため、PY_PYTHON は全く考慮されません。)</li>
<li><code class="docutils literal"><span class="pre">PY_PYTHON=3</span></code> で <code class="docutils literal"><span class="pre">PY_PYTHON3=3.1</span></code> の場合、<code class="docutils literal"><span class="pre">python</span></code> および <code class="docutils literal"><span class="pre">python3</span></code> はどちらも 3.1 を使用します</li>
</ul>
<p>環境変数に加え、同じ設定をランチャが使う INI ファイルで構成することができます。INI ファイルの該当するセクションは <code class="docutils literal"><span class="pre">[defaults]</span></code> と呼ばれ、キー名は環境変数のキー名から <code class="docutils literal"><span class="pre">PY_</span></code> という接頭辞を取ったものと同じです (INI ファイルのキー名は大文字小文字を区別しないことにご注意ください)。環境変数の内容は INI ファイルでの指定を上書きします。</p>
<p>例えば:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">PY_PYTHON=3.1</span></code> と設定することは、INI ファイルに下記が含まれることと等価です:</li>
</ul>
<div class="highlight-ini"><div class="highlight"><pre><span></span><span class="k">[defaults]</span>
<span class="na">python</span><span class="o">=</span><span class="s">3.1</span>
</pre></div>
</div>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">PY_PYTHON=3</span></code> と <code class="docutils literal"><span class="pre">PY_PYTHON3=3.1</span></code> を設定することは、INI ファイルに下記が含まれることと等価です:</li>
</ul>
<div class="highlight-ini"><div class="highlight"><pre><span></span><span class="k">[defaults]</span>
<span class="na">python</span><span class="o">=</span><span class="s">3</span>
<span class="na">python3</span><span class="o">=</span><span class="s">3.1</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="diagnostics">
<h3>3.4.5. 診断<a class="headerlink" href="#diagnostics" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>環境変数 <code class="docutils literal"><span class="pre">PYLAUNCH_DEBUG</span></code> が設定されていたら、設定値が何であっても、ランチャは診断情報を stderr (つまりコンソール) に出力します。この情報のメッセージは詳細で <em>しかも</em> きついものですが、どういったバージョンの Python が検知されたか、なぜ特定のバージョンが選択されたか、そして、対象の Python を実行するのに使われた正確なコマンドラインを教えてくれます。</p>
</div>
</div>
<div class="section" id="finding-modules">
<span id="id1"></span><h2>3.5. モジュールの検索<a class="headerlink" href="#finding-modules" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>Python は通常そのライブラリ (と site-packages フォルダ) をインストールしたディレクトリに格納します。そのため、 Python を <code class="file docutils literal"><span class="pre">C:\Python\</span></code> ディレクトリにインストールしたとすると、デフォルトのライブラリは <code class="file docutils literal"><span class="pre">C:\Python\Lib\</span></code> に存在し、サードパーティーのモジュールは <code class="file docutils literal"><span class="pre">C:\Python\Lib\site-packages\</span></code> に格納することになります。</p>
<p>To completely override <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a>, create a <code class="docutils literal"><span class="pre">._pth</span></code> file with the same
name as the DLL (<code class="docutils literal"><span class="pre">python36._pth</span></code>) or the executable (<code class="docutils literal"><span class="pre">python._pth</span></code>) and
specify one line for each path to add to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a>. The file based on the
DLL name overrides the one based on the executable, which allows paths to be
restricted for any program loading the runtime if desired.</p>
<p>When the file exists, all registry and environment variables are ignored,
isolated mode is enabled, and <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal"><span class="pre">site</span></code></a> is not imported unless one line in the
file specifies <code class="docutils literal"><span class="pre">import</span> <span class="pre">site</span></code>. Blank paths and lines starting with <code class="docutils literal"><span class="pre">#</span></code> are
ignored. Each path may be absolute or relative to the location of the file.
Import statements other than to <code class="docutils literal"><span class="pre">site</span></code> are not permitted, and arbitrary code
cannot be specified.</p>
<p>Note that <code class="docutils literal"><span class="pre">.pth</span></code> files (without leading underscore) will be processed normally
by the <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal"><span class="pre">site</span></code></a> module.</p>
<p>When no <code class="docutils literal"><span class="pre">._pth</span></code> file is found, this is how <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a> is populated on
Windows:</p>
<ul class="simple">
<li>最初に空のエントリが追加されます。これはカレントディレクトリを指しています。</li>
<li>その次に、 <span class="target" id="index-67"></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> 環境変数が存在するとき、 <a class="reference internal" href="cmdline.html#using-on-envvars"><span class="std std-ref">環境変数</span></a> で解説されているように追加されます。 Windows ではドライブ識別子 (<code class="docutils literal"><span class="pre">C:\</span></code> など)と区別するために、この環境変数に含まれるパスの区切り文字はセミコロンでなければならない事に注意してください。</li>
<li>追加で "アプリケーションのパス" を <code class="docutils literal"><span class="pre">HKEY_CURRENT_USER</span></code> か <code class="docutils literal"><span class="pre">HKEY_LOCAL_MACHINE</span></code> の中の <code class="samp docutils literal"><span class="pre">\SOFTWARE\Python\PythonCore\</span><em><span class="pre">version</span></em><span class="pre">\PythonPath</span></code> のサブキーとして登録することができます。サブキーはデフォルト値としてセミコロンで区切られたパス文字列を持つことができ、書くパスが <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a> に追加されます。 (既存のインストーラーはすべて HKLM しか利用しないので、 HKCU は通常空です)</li>
<li>If the environment variable <span class="target" id="index-18"></span><a class="reference internal" href="cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONHOME</span></code></a> is set, it is assumed as
"Python Home". Otherwise, the path of the main Python executable is used to
locate a "landmark file" (either <code class="docutils literal"><span class="pre">Lib\os.py</span></code> or <code class="docutils literal"><span class="pre">pythonXY.zip</span></code>) to deduce
the "Python Home". If a Python home is found, the relevant sub-directories
added to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal"><span class="pre">sys.path</span></code></a> (<code class="docutils literal"><span class="pre">Lib</span></code>, <code class="docutils literal"><span class="pre">plat-win</span></code>, etc) are based on that
folder. Otherwise, the core Python path is constructed from the PythonPath
stored in the registry.</li>
<li>Python Home が見つからず、環境変数 <span class="target" id="index-68"></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> が指定されず、レジストリエントリが見つからなかった場合、関連するデフォルトのパスが利用されます (例: <code class="docutils literal"><span class="pre">.\Lib;.\plat-win</span></code> など)。</li>
</ul>
<p>メインの実行ファイルと同じ場所か一つ上のディレクトリに <code class="docutils literal"><span class="pre">pyvenv.cfg</span></code> がある場合、以下の異なった規則が適用されます:</p>
<ul class="simple">
<li><span class="target" id="index-69"></span><a class="reference internal" href="cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONHOME</span></code></a> が設定されておらず、 <code class="docutils literal"><span class="pre">home</span></code> が絶対パスの場合、home 推定の際メインの実行ファイルから推定するのではなくこのパスを使います。</li>
</ul>
<p>結果としてこうなります:</p>
<ul class="simple">
<li><code class="file docutils literal"><span class="pre">python.exe</span></code> かそれ以外の Python ディレクトリにある .exe ファイルを実行したとき (インストールされている場合でも PCbuild から直接実行されている場合でも) core path が利用され、レジストリ内の core path は無視されます。それ以外のレジストリの "application paths" は常に読み込まれます。</li>
<li>Python が他の .exe ファイル (他のディレクトリに存在する場合や、COM経由で組み込まれる場合など) にホストされている場合は、 "Python Home" は推定されず、レジストリにある core path が利用されます。それ以外のレジストリの "application paths" は常に読み込まれます。</li>
<li>Python がその home を見つけられず、レジストリの値もない場合 (これはいくつかのとてもおかしなインストレーションセットアップの凍結された .exe)、パスは最小限のデフォルトとして相対パスが使われます。</li>
</ul>
<p>自身のアプリケーションや配布物に Python をバンドルしたい場合には、以下の助言 (のいずれかまたは組合せ) によりほかのインストレーションとの衝突を避けることができます:</p>
<ul class="simple">
<li>Include a <code class="docutils literal"><span class="pre">._pth</span></code> file alongside your executable containing the
directories to include. This will ignore paths listed in the registry and
environment variables, and also ignore <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal"><span class="pre">site</span></code></a> unless <code class="docutils literal"><span class="pre">import</span> <span class="pre">site</span></code> is
listed.</li>
<li>If you are loading <code class="file docutils literal"><span class="pre">python3.dll</span></code> or <code class="file docutils literal"><span class="pre">python36.dll</span></code> in your own
executable, explicitly call <a class="reference internal" href="../c-api/init.html#c.Py_SetPath" title="Py_SetPath"><code class="xref c c-func docutils literal"><span class="pre">Py_SetPath()</span></code></a> or (at least)
<a class="reference internal" href="../c-api/init.html#c.Py_SetProgramName" title="Py_SetProgramName"><code class="xref c c-func docutils literal"><span class="pre">Py_SetProgramName()</span></code></a> before <a class="reference internal" href="../c-api/init.html#c.Py_Initialize" title="Py_Initialize"><code class="xref c c-func docutils literal"><span class="pre">Py_Initialize()</span></code></a>.</li>
<li>自身のアプリケーションから <code class="file docutils literal"><span class="pre">python.exe</span></code> を起動する前に、 <span class="target" id="index-70"></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> をクリアしたり上書きし、 <span class="target" id="index-71"></span><a class="reference internal" href="cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal"><span class="pre">PYTHONHOME</span></code></a> をセットしてください。</li>
<li>If you cannot use the previous suggestions (for example, you are a
distribution that allows people to run <code class="file docutils literal"><span class="pre">python.exe</span></code> directly), ensure
that the landmark file (<code class="file docutils literal"><span class="pre">Lib\os.py</span></code>) exists in your install directory.
(Note that it will not be detected inside a ZIP file, but a correctly named
ZIP file will be detected instead.)</li>
</ul>
<p>これらはシステムワイドにインストールされたファイルが、あなたのアプリケーションにバンドルされた標準ライブラリのコピーに優先しないようにします。これをしなければあなたのアプリケーションのユーザは、何かしら問題を抱えるかもしれません。上で列挙した最初の提案が最善です。ほかのものはレジストリ内の非標準のパスやユーザの site-packages の影響を少し受けやすいからです。</p>
<div class="versionchanged">
<blockquote>
<div><span class="versionmodified">バージョン 3.6 で変更: </span><ul class="simple">
<li>Adds <code class="docutils literal"><span class="pre">._pth</span></code> file support and removes <code class="docutils literal"><span class="pre">applocal</span></code> option from
<code class="docutils literal"><span class="pre">pyvenv.cfg</span></code>.</li>
<li>Adds <code class="docutils literal"><span class="pre">pythonXX.zip</span></code> as a potential landmark when directly adjacent
to the executable.</li>
</ul>
</div></blockquote>
</div>
<div class="deprecated">
<blockquote>
<div><span class="versionmodified">バージョン 3.6 で撤廃: </span><p>Modules specified in the registry under <code class="docutils literal"><span class="pre">Modules</span></code> (not <code class="docutils literal"><span class="pre">PythonPath</span></code>)
may be imported by <a class="reference internal" href="../library/importlib.html#importlib.machinery.WindowsRegistryFinder" title="importlib.machinery.WindowsRegistryFinder"><code class="xref py py-class docutils literal"><span class="pre">importlib.machinery.WindowsRegistryFinder</span></code></a>.
This finder is enabled on Windows in 3.6.0 and earlier, but may need to
be explicitly added to <a class="reference internal" href="../library/sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-attr docutils literal"><span class="pre">sys.meta_path</span></code></a> in the future.</p>
</div></blockquote>
</div>
</div>
<div class="section" id="additional-modules">
<h2>3.6. 追加のモジュール<a class="headerlink" href="#additional-modules" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>Python は全プラットフォーム互換を目指していますが、 Windows にしかないユニークな機能もあります。標準ライブラリと外部のライブラリの両方で、幾つかのモジュールと、そういった機能を使うためのスニペットがあります。</p>
<p>Windows 固有の標準モジュールは、 <a class="reference internal" href="../library/windows.html#mswin-specific-services"><span class="std std-ref">MS Windows 固有のサービス</span></a> に書かれています。</p>
<div class="section" id="pywin32">
<h3>3.6.1. PyWin32<a class="headerlink" href="#pywin32" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>The <a class="reference external" href="https://pypi.python.org/pypi/pywin32">PyWin32</a> module by Mark Hammond
is a collection of modules for advanced Windows-specific support. This includes
utilities for:</p>
<ul class="simple">
<li><a class="reference external" href="https://www.microsoft.com/com/">Component Object Model</a> (COM)</li>
<li>Win32 API 呼び出し</li>
<li>レジストリ</li>
<li>イベントログ</li>
<li><a class="reference external" href="https://msdn.microsoft.com/en-us/library/fe1cf721%28VS.80%29.aspx">Microsoft Foundation Classes</a> (MFC) ユーザーインターフェイス</li>
</ul>
<p><a class="reference external" href="https://web.archive.org/web/20060524042422/https://www.python.org/windows/pythonwin/">PythonWin</a> は PyWin32 に付属している、サンプルのMFCアプリケーションです。これはビルトインのデバッガを含む、組み込み可能なIDEです。</p>
<div class="admonition seealso">
<p class="first admonition-title">参考</p>
<dl class="last docutils">
<dt><a class="reference external" href="http://timgolden.me.uk/python/win32_how_do_i.html">Win32 How Do I…?</a></dt>
<dd>by Tim Golden</dd>
<dt><a class="reference external" href="http://www.boddie.org.uk/python/COM.html">Python and COM</a></dt>
<dd>by David and Paul Boddie</dd>
</dl>
</div>
</div>
<div class="section" id="cx-freeze">
<h3>3.6.2. cx_Freeze<a class="headerlink" href="#cx-freeze" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p><a class="reference external" href="http://cx-freeze.sourceforge.net/">cx_Freeze</a> は <a class="reference internal" href="../library/distutils.html#module-distutils" title="distutils: Support for building and installing Python modules into an existing Python installation."><code class="xref py py-mod docutils literal"><span class="pre">distutils</span></code></a> 拡張 (<a class="reference internal" href="../distutils/extending.html#extending-distutils"><span class="std std-ref">Distutilsの拡張</span></a> を参照) で、 Python スクリプトを Windows 実行可能プログラム (<code class="file docutils literal"><em><span class="pre">*</span></em><span class="pre">.exe</span></code> ファイル) にラップします。これを使えば、ユーザーに Python のインストールをさせなくても、アプリケーションを配布することができます。</p>
</div>
<div class="section" id="wconio">
<h3>3.6.3. WConio<a class="headerlink" href="#wconio" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>Python の進んだターミナル制御レイヤである <a class="reference internal" href="../library/curses.html#module-curses" title="curses: An interface to the curses library, providing portable terminal handling. (Unix)"><code class="xref py py-mod docutils literal"><span class="pre">curses</span></code></a> は、 Unix ライクシステムでしか使うことができません。逆に Windows 専用のライブラリ、 Windows Console I/O for Python があります。</p>
<p><a class="reference external" href="http://newcenturycomputers.net/projects/wconio.html">WConio</a> は Turbo-C の <code class="file docutils literal"><span class="pre">CONIO.H</span></code> のラッパーで、テキストユーザーインタフェースを作成するために利用することができます。</p>
</div>
</div>
<div class="section" id="compiling-python-on-windows">
<h2>3.7. Windows 上で Python をコンパイルする<a class="headerlink" href="#compiling-python-on-windows" title="このヘッドラインへのパーマリンク">¶</a></h2>
<p>If you want to compile CPython yourself, first thing you should do is get the
<a class="reference external" href="https://www.python.org/downloads/source/">source</a>. You can download either the
latest release’s source or just grab a fresh <a class="reference external" href="https://devguide.python.org/setup/#getting-the-source-code">checkout</a>.</p>
<p>ソースツリーには Microsoft Visual Studio 2015 でのビルドのソリューションファイルとプロジェクトファイルが含まれていて、これが公式の Python リリースに使われているコンパイラです。これらファイルは <code class="file docutils literal"><span class="pre">PCbuild</span></code> ディレクトリ内にあります。</p>
<p>ビルドプロセスについての一般的な情報は、<code class="file docutils literal"><span class="pre">PCbuild/readme.txt</span></code> にあります。</p>
<p>拡張モジュールについては、 <a class="reference internal" href="../extending/windows.html#building-on-windows"><span class="std std-ref">Windows 上での C および C++ 拡張モジュールのビルド</span></a> を参照してください。</p>
<div class="admonition seealso">
<p class="first admonition-title">参考</p>
<dl class="last docutils">
<dt><a class="reference external" href="http://sebsauvage.net/python/mingw.html">Python + Windows + distutils + SWIG + gcc MinGW</a></dt>
<dd>or "Creating Python extensions in C/C++ with SWIG and compiling them with
MinGW gcc under Windows" or "Installing Python extension with distutils
and without Microsoft Visual C++" by Sébastien Sauvage, 2003</dd>
<dt><a class="reference external" href="http://oldwiki.mingw.org/index.php/Python%20extensions">MingW – Python extensions</a></dt>
<dd>by Trent Apted et al, 2007</dd>
</dl>
</div>
</div>
<div class="section" id="embedded-distribution">
<h2>3.8. Python 埋め込みのための配布<a class="headerlink" href="#embedded-distribution" title="このヘッドラインへのパーマリンク">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified">バージョン 3.5 で追加.</span></p>
</div>
<p>埋め込み用の配布 (embedded distribution) は、最小限の Python 環境を含んだ ZIP ファイルです。これは、エンドユーザから直接的にアクセスされるのではなく何かアプリケーションの一部として動作することを意図したものです。</p>
<p>When extracted, the embedded distribution is (almost) fully isolated from the
user’s system, including environment variables, system registry settings, and
installed packages. The standard library is included as pre-compiled and
optimized <code class="docutils literal"><span class="pre">.pyc</span></code> files in a ZIP, and <code class="docutils literal"><span class="pre">python3.dll</span></code>, <code class="docutils literal"><span class="pre">python36.dll</span></code>,
<code class="docutils literal"><span class="pre">python.exe</span></code> and <code class="docutils literal"><span class="pre">pythonw.exe</span></code> are all provided. Tcl/tk (including all
dependants, such as Idle), pip and the Python documentation are not included.</p>
<div class="admonition note">
<p class="first admonition-title">注釈</p>
<p class="last">埋め込み用配布には <a class="reference external" href="https://www.microsoft.com/en-us/download/details.aspx?id=48145">Microsoft C Runtime</a> は含まれません。これを提供するのはアプリケーションのインストーラの責務です。そのランタイムは既に以前にユーザのシステムにインストール済みかもしれませんし、Windows Update により自動で更新されているかもしれません。このことはシステムディレクトリに <code class="docutils literal"><span class="pre">ucrtbase.dll</span></code> があるか探せばわかります。</p>
</div>
<p>サードパーティのパッケージはアプリケーションのインストーラによって、埋め込み用配布と同じ場所にインストールされるべきです。通常の Python インストレーションのように依存性管理に pip を使うことは、この配布ではサポートされません。ですが、ちょっとした注意を払えば、自動更新のために pip を含めて利用することはできるかもしれません。一般的には、ユーザに更新を提供する前に開発者が新しいバージョンとの互換性を保証できるよう、サードパーティーのパッケージはアプリケーションの一部として扱われるべきです ("vendoring")。</p>
<p>この配布の 2 つのお勧めできるユースケースを、以下で説明します。</p>
<div class="section" id="python-application">
<h3>3.8.1. Python アプリケーション<a class="headerlink" href="#python-application" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>Python で記述された、必ずしもユーザにその事実を意識させる必要のないアプリケーションです。埋め込み用配布はこのケースで、インストールパッケージ内に Python のプライベートバージョンを含めるのに使えるでしょう。その事実がどのように透過的であるべきかに依存して (あるいは逆に、どのようにプロフェッショナルにみえるべきか)、2 つの選択肢があります。</p>
<p>ランチャとなる特別な実行ファイルを使うことはちょっとしたコーディングを必要としますが、ユーザにとっては最も透過的なユーザ体験となります。カスタマイズされたランチャでは、何もしなければ Python で実行されるプログラムの明白な目印はありません; アイコンはカスタマイズし、会社名やバージョン情報を指定し、ファイルの関連付けがそれに相応しく振舞うようにできます。ほとんどのケースではカスタムランチャは、ハードコードされたコマンドライン文字列で単純に <code class="docutils literal"><span class="pre">Py_Main</span></code> を呼び出すので済むはずです。</p>
<p>より簡単なアプローチは、 <code class="docutils literal"><span class="pre">python.exe</span></code> または <code class="docutils literal"><span class="pre">pythonw.exe</span></code> を必要なコマンドライン引数とともに直接呼び出すバッチファイルかショートカットを提供することです。この場合、そのアプリケーションは実際の名前ではなく Python であるようにみえるので、ほかに動作している Python プロセスやファイルの関連付けと区別するのにユーザが困るかもしれません。</p>
<p>後者のアプローチではパッケージは、パス上で利用可能であることを保証するために、Python 実行ファイルと同じディレクトリにインストールされるべきです。特別なランチャの場合はアプリケーション起動前に検索パスを指定する機会があるので、パッケージはほかの場所に配置できます。</p>
</div>
<div class="section" id="embedding-python">
<h3>3.8.2. Python の埋め込み<a class="headerlink" href="#embedding-python" title="このヘッドラインへのパーマリンク">¶</a></h3>
<p>ネイティブコードで書かれ、時々スクリプト言語のようなものを必要とするようなアプリケーションです。Python 埋め込み用の配布はこの目的に使えます。一般的に、アプリケーションの大半がネイティブコード内にあり、一部が <code class="docutils literal"><span class="pre">python.exe</span></code> を呼び出すか、直接的に <code class="docutils literal"><span class="pre">python3.dll</span></code> を使います。どちらのケースでも、ロード可能な Python インタプリタを提供するのには、埋め込み用の配布を展開してアプリケーションのインストレーションのサブディレクトリに置くことで十分です。</p>
<p>アプリケーションが使うパッケージは、インタプリタ初期化前に検索パスを指定する機会があるので、任意の場所にインストールできます。また、埋め込み用配布を使うのと通常の Python インストレーションを使うのとでの根本的な違いはありません。</p>
</div>
</div>
<div class="section" id="other-resources">
<h2>3.9. その他のリソース<a class="headerlink" href="#other-resources" title="このヘッドラインへのパーマリンク">¶</a></h2>
<div class="admonition seealso">
<p class="first admonition-title">参考</p>
<dl class="last docutils">
<dt><a class="reference external" href="http://shop.oreilly.com/product/9781565926219.do">Python Programming On Win32</a></dt>
<dd>"Help for Windows Programmers"
by Mark Hammond and Andy Robinson, O’Reilly Media, 2000,
ISBN 1-56592-621-8</dd>
<dt><a class="reference external" href="http://www.imladris.com/Scripts/PythonForWindows.html">A Python for Windows Tutorial</a></dt>
<dd>by Amanda Birmingham, 2004</dd>
<dt><span class="target" id="index-23"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0397"><strong>PEP 397</strong></a> - Python launcher for Windows</dt>
<dd>Python の配布物へのランチャ同梱の提案。</dd>
</dl>
</div>
</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="#">3. Windows で Python を使う</a><ul>
<li><a class="reference internal" href="#installing-python">3.1. Python のインストール</a><ul>
<li><a class="reference internal" href="#supported-versions">3.1.1. サポートされているバージョン</a></li>
<li><a class="reference internal" href="#installation-steps">3.1.2. インストール手順</a></li>
<li><a class="reference internal" href="#removing-the-max-path-limitation">3.1.3. MAX_PATH の制限を除去する</a></li>
<li><a class="reference internal" href="#installing-without-ui">3.1.4. インストーラの GUI なしでインストールする</a></li>
<li><a class="reference internal" href="#installing-without-downloading">3.1.5. ダウンロード不要なインストール</a></li>
<li><a class="reference internal" href="#modifying-an-install">3.1.6. インストール後の変更</a></li>
<li><a class="reference internal" href="#other-platforms">3.1.7. ほかのプラットフォーム</a></li>
</ul>
</li>
<li><a class="reference internal" href="#alternative-bundles">3.2. 別のバンドル</a></li>
<li><a class="reference internal" href="#configuring-python">3.3. Python を構成する</a><ul>
<li><a class="reference internal" href="#excursus-setting-environment-variables">3.3.1. 補足: 環境変数の設定</a></li>
<li><a class="reference internal" href="#finding-the-python-executable">3.3.2. Python 実行ファイルを見つける</a></li>
</ul>
</li>
<li><a class="reference internal" href="#python-launcher-for-windows">3.4. Windows の Python ランチャ</a><ul>
<li><a class="reference internal" href="#getting-started">3.4.1. 最初に</a><ul>
<li><a class="reference internal" href="#from-the-command-line">3.4.1.1. コマンドラインから起動する</a></li>
<li><a class="reference internal" href="#virtual-environments">3.4.1.2. 仮想環境 (Virtual environments)</a></li>
<li><a class="reference internal" href="#from-a-script">3.4.1.3. スクリプトから起動する</a></li>
<li><a class="reference internal" href="#from-file-associations">3.4.1.4. ファイルの関連付けから起動する</a></li>
</ul>
</li>
<li><a class="reference internal" href="#shebang-lines">3.4.2. シェバン (shebang) 行</a></li>
<li><a class="reference internal" href="#arguments-in-shebang-lines">3.4.3. シェバン行の引数</a></li>
<li><a class="reference internal" href="#customization">3.4.4. カスタマイズ</a><ul>
<li><a class="reference internal" href="#customization-via-ini-files">3.4.4.1. INI ファイルによるカスタマイズ</a></li>
<li><a class="reference internal" href="#customizing-default-python-versions">3.4.4.2. デフォルトのPythonバージョンのカスタマイズ</a></li>
</ul>
</li>
<li><a class="reference internal" href="#diagnostics">3.4.5. 診断</a></li>
</ul>
</li>
<li><a class="reference internal" href="#finding-modules">3.5. モジュールの検索</a></li>
<li><a class="reference internal" href="#additional-modules">3.6. 追加のモジュール</a><ul>
<li><a class="reference internal" href="#pywin32">3.6.1. PyWin32</a></li>
<li><a class="reference internal" href="#cx-freeze">3.6.2. cx_Freeze</a></li>
<li><a class="reference internal" href="#wconio">3.6.3. WConio</a></li>
</ul>
</li>
<li><a class="reference internal" href="#compiling-python-on-windows">3.7. Windows 上で Python をコンパイルする</a></li>
<li><a class="reference internal" href="#embedded-distribution">3.8. Python 埋め込みのための配布</a><ul>
<li><a class="reference internal" href="#python-application">3.8.1. Python アプリケーション</a></li>
<li><a class="reference internal" href="#embedding-python">3.8.2. Python の埋め込み</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-resources">3.9. その他のリソース</a></li>
</ul>
</li>
</ul>
<h4>前のトピックへ</h4>
<p class="topless"><a href="unix.html"
title="前の章へ">2. Unix プラットフォームで Python を使う</a></p>
<h4>次のトピックへ</h4>
<p class="topless"><a href="mac.html"
title="次の章へ">4. Macintosh で 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/windows.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="mac.html" title="4. Macintosh で Python を使う"
>次へ</a> |</li>
<li class="right" >
<a href="unix.html" title="2. Unix プラットフォームで 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>