-
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathcompileall.html
More file actions
716 lines (647 loc) · 55.1 KB
/
compileall.html
File metadata and controls
716 lines (647 loc) · 55.1 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
<!DOCTYPE html>
<html lang="zh-TW" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>compileall --- 位元組編譯 Python 函式庫 — Python 3.14.5 說明文件</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=4365c8fe" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=8c54008b"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/translations.js?v=cbf116e0"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.14.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="版權所有" href="../copyright.html" />
<link rel="next" title="dis --- Python bytecode 的反組譯器" href="dis.html" />
<link rel="prev" title="py_compile — 編譯 Python 來源檔案" href="py_compile.html" />
<link rel="canonical" href="https://docs.python.org/3/library/compileall.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg">
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="選單">
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo">
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
</svg>
<input placeholder="快速搜索" aria-label="快速搜索" type="search" name="q">
<input type="submit" value="前往">
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
主題
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>自動</option>
<option value="light">淺色模式</option>
<option value="dark">深色模式</option>
</select>
</label>
<div>
<h3><a href="../contents.html">目錄</a></h3>
<ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> --- 位元組編譯 Python 函式庫</a><ul>
<li><a class="reference internal" href="#command-line-use">Command-line use</a></li>
<li><a class="reference internal" href="#public-functions">Public functions</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>上個主題</h4>
<p class="topless"><a href="py_compile.html"
title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> — 編譯 Python 來源檔案</a></p>
</div>
<div>
<h4>下個主題</h4>
<p class="topless"><a href="dis.html"
title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> --- Python bytecode 的反組譯器</a></p>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const title = document.querySelector('meta[property="og:title"]').content;
const elements = document.querySelectorAll('.improvepage');
const pageurl = window.location.href.split('?')[0];
elements.forEach(element => {
const url = new URL(element.href.split('?')[0].replace("-nojs", ""));
url.searchParams.set('pagetitle', title);
url.searchParams.set('pageurl', pageurl);
url.searchParams.set('pagesource', "library/compileall.rst");
element.href = url.toString();
});
});
</script>
<div role="note" aria-label="source link">
<h3>此頁面</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">回報錯誤</a></li>
<li><a class="improvepage" href="../improve-page-nojs.html">改進此頁面</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/library/compileall.rst?plain=1"
rel="nofollow">顯示原始碼
</a>
</li>
<li>
<a href="https://github.com/python/python-docs-zh-TW/blob/3.14/library/compileall.po?plain=1"
rel="nofollow">顯示翻譯原始碼</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<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="dis.html" title="dis --- Python bytecode 的反組譯器"
accesskey="N">下一頁</a> |</li>
<li class="right" >
<a href="py_compile.html" title="py_compile — 編譯 Python 來源檔案"
accesskey="P">上一頁</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.14.5 Documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python 標準函式庫 (Standard Library)</a> »</li>
<li class="nav-item nav-item-2"><a href="language.html" accesskey="U">Python 語言服務</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> --- 位元組編譯 Python 函式庫</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="search" name="q" id="search-box">
<input type="submit" value="前往">
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
主題
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>自動</option>
<option value="light">淺色模式</option>
<option value="dark">深色模式</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-compileall">
<span id="compileall-byte-compile-python-libraries"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> --- 位元組編譯 Python 函式庫<a class="headerlink" href="#module-compileall" title="連結到這個標頭">¶</a></h1>
<p><strong>原始碼:</strong><a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.14/Lib/compileall.py">Lib/compileall.py</a></p>
<hr class="docutils" />
<p>This module provides some utility functions to support installing Python
libraries. These functions compile Python source files in a directory tree.
This module can be used to create the cached byte-code files at library
installation time, which makes them available for use even by users who don't
have write permission to the library directories.</p>
<div class="availability docutils container">
<p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">可用性</span></a>: not WASI.</p>
<p>此模組在 WebAssembly 平台上不起作用或無法使用。更多資訊請參閱 <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly 平台</span></a>。</p>
</div>
<section id="command-line-use">
<span id="compileall-cli"></span><h2>Command-line use<a class="headerlink" href="#command-line-use" title="連結到這個標頭">¶</a></h2>
<p>This module can work as a script (using <strong class="program">python -m compileall</strong>) to
compile Python sources.</p>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-arg-directory">
<span class="sig-name descname"><span class="pre">directory</span></span><span class="sig-prename descclassname"> <span class="pre">...</span></span><a class="headerlink" href="#cmdoption-compileall-arg-directory" title="連結到這個定義">¶</a></dt>
<dt class="sig sig-object std" id="cmdoption-compileall-arg-file">
<span class="sig-name descname"><span class="pre">file</span></span><span class="sig-prename descclassname"> <span class="pre">...</span></span><a class="headerlink" href="#cmdoption-compileall-arg-file" title="連結到這個定義">¶</a></dt>
<dd><p>Positional arguments are files to compile or directories that contain
source files, traversed recursively. If no argument is given, behave as if
the command line was <code class="samp docutils literal notranslate"><span class="pre">-l</span> <em><span class="pre"><directories</span> <span class="pre">from</span> <span class="pre">sys.path></span></em></code>.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-l">
<span class="sig-name descname"><span class="pre">-l</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-l" title="連結到這個定義">¶</a></dt>
<dd><p>Do not recurse into subdirectories, only compile source code files directly
contained in the named or implied directories.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-f">
<span class="sig-name descname"><span class="pre">-f</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-f" title="連結到這個定義">¶</a></dt>
<dd><p>Force rebuild even if timestamps are up-to-date.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-q">
<span class="sig-name descname"><span class="pre">-q</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-q" title="連結到這個定義">¶</a></dt>
<dd><p>Do not print the list of files compiled. If passed once, error messages will
still be printed. If passed twice (<code class="docutils literal notranslate"><span class="pre">-qq</span></code>), all output is suppressed.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-d">
<span class="sig-name descname"><span class="pre">-d</span></span><span class="sig-prename descclassname"> <span class="pre">destdir</span></span><a class="headerlink" href="#cmdoption-compileall-d" title="連結到這個定義">¶</a></dt>
<dd><p>Directory prepended to the path to each file being compiled. This will
appear in compilation time tracebacks, and is also compiled in to the
byte-code file, where it will be used in tracebacks and other messages in
cases where the source file does not exist at the time the byte-code file is
executed.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-s">
<span class="sig-name descname"><span class="pre">-s</span></span><span class="sig-prename descclassname"> <span class="pre">strip_prefix</span></span><a class="headerlink" href="#cmdoption-compileall-s" title="連結到這個定義">¶</a></dt>
<dd><p>Remove the given prefix from paths recorded in the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files.
Paths are made relative to the prefix.</p>
<p>This option can be used with <code class="docutils literal notranslate"><span class="pre">-p</span></code> but not with <code class="docutils literal notranslate"><span class="pre">-d</span></code>.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-p">
<span class="sig-name descname"><span class="pre">-p</span></span><span class="sig-prename descclassname"> <span class="pre">prepend_prefix</span></span><a class="headerlink" href="#cmdoption-compileall-p" title="連結到這個定義">¶</a></dt>
<dd><p>Prepend the given prefix to paths recorded in the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files.
Use <code class="docutils literal notranslate"><span class="pre">-p</span> <span class="pre">/</span></code> to make the paths absolute.</p>
<p>This option can be used with <code class="docutils literal notranslate"><span class="pre">-s</span></code> but not with <code class="docutils literal notranslate"><span class="pre">-d</span></code>.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-x">
<span class="sig-name descname"><span class="pre">-x</span></span><span class="sig-prename descclassname"> <span class="pre">regex</span></span><a class="headerlink" href="#cmdoption-compileall-x" title="連結到這個定義">¶</a></dt>
<dd><p>regex is used to search the full path to each file considered for
compilation, and if the regex produces a match, the file is skipped.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-i">
<span class="sig-name descname"><span class="pre">-i</span></span><span class="sig-prename descclassname"> <span class="pre">list</span></span><a class="headerlink" href="#cmdoption-compileall-i" title="連結到這個定義">¶</a></dt>
<dd><p>Read the file <code class="docutils literal notranslate"><span class="pre">list</span></code> and add each line that it contains to the list of
files and directories to compile. If <code class="docutils literal notranslate"><span class="pre">list</span></code> is <code class="docutils literal notranslate"><span class="pre">-</span></code>, read lines from
<code class="docutils literal notranslate"><span class="pre">stdin</span></code>.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-b">
<span class="sig-name descname"><span class="pre">-b</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-b" title="連結到這個定義">¶</a></dt>
<dd><p>Write the byte-code files to their legacy locations and names, which may
overwrite byte-code files created by another version of Python. The default
is to write files to their <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a> locations and names, which allows
byte-code files from multiple versions of Python to coexist.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-r">
<span class="sig-name descname"><span class="pre">-r</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-r" title="連結到這個定義">¶</a></dt>
<dd><p>Control the maximum recursion level for subdirectories.
If this is given, then <code class="docutils literal notranslate"><span class="pre">-l</span></code> option will not be taken into account.
<strong class="program">python -m compileall <directory> -r 0</strong> is equivalent to
<strong class="program">python -m compileall <directory> -l</strong>.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-j">
<span class="sig-name descname"><span class="pre">-j</span></span><span class="sig-prename descclassname"> <span class="pre">N</span></span><a class="headerlink" href="#cmdoption-compileall-j" title="連結到這個定義">¶</a></dt>
<dd><p>Use <em>N</em> workers to compile the files within the given directory.
If <code class="docutils literal notranslate"><span class="pre">0</span></code> is used, then the result of <a class="reference internal" href="os.html#os.process_cpu_count" title="os.process_cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.process_cpu_count()</span></code></a>
will be used.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-invalidation-mode">
<span class="sig-name descname"><span class="pre">--invalidation-mode</span></span><span class="sig-prename descclassname"> <span class="pre">[timestamp|checked-hash|unchecked-hash]</span></span><a class="headerlink" href="#cmdoption-compileall-invalidation-mode" title="連結到這個定義">¶</a></dt>
<dd><p>Control how the generated byte-code files are invalidated at runtime.
The <code class="docutils literal notranslate"><span class="pre">timestamp</span></code> value, means that <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files with the source timestamp
and size embedded will be generated. The <code class="docutils literal notranslate"><span class="pre">checked-hash</span></code> and
<code class="docutils literal notranslate"><span class="pre">unchecked-hash</span></code> values cause hash-based pycs to be generated. Hash-based
pycs embed a hash of the source file contents rather than a timestamp. See
<a class="reference internal" href="../reference/import.html#pyc-invalidation"><span class="std std-ref">被快取的位元組碼的無效化</span></a> for more information on how Python validates
bytecode cache files at runtime.
The default is <code class="docutils literal notranslate"><span class="pre">timestamp</span></code> if the <span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">SOURCE_DATE_EPOCH</span></code> environment
variable is not set, and <code class="docutils literal notranslate"><span class="pre">checked-hash</span></code> if the <code class="docutils literal notranslate"><span class="pre">SOURCE_DATE_EPOCH</span></code>
environment variable is set.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-o">
<span class="sig-name descname"><span class="pre">-o</span></span><span class="sig-prename descclassname"> <span class="pre">level</span></span><a class="headerlink" href="#cmdoption-compileall-o" title="連結到這個定義">¶</a></dt>
<dd><p>Compile with the given optimization level. May be used multiple times
to compile for multiple levels at a time (for example,
<code class="docutils literal notranslate"><span class="pre">compileall</span> <span class="pre">-o</span> <span class="pre">1</span> <span class="pre">-o</span> <span class="pre">2</span></code>).</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-e">
<span class="sig-name descname"><span class="pre">-e</span></span><span class="sig-prename descclassname"> <span class="pre">dir</span></span><a class="headerlink" href="#cmdoption-compileall-e" title="連結到這個定義">¶</a></dt>
<dd><p>Ignore symlinks pointing outside the given directory.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-compileall-hardlink-dupes">
<span class="sig-name descname"><span class="pre">--hardlink-dupes</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-hardlink-dupes" title="連結到這個定義">¶</a></dt>
<dd><p>If two <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files with different optimization level have
the same content, use hard links to consolidate duplicate files.</p>
</dd></dl>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版的變更: </span>新增選項 <code class="docutils literal notranslate"><span class="pre">-i</span></code>、<code class="docutils literal notranslate"><span class="pre">-b</span></code> 與 <code class="docutils literal notranslate"><span class="pre">-h</span></code>。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版的變更: </span>Added the <code class="docutils literal notranslate"><span class="pre">-j</span></code>, <code class="docutils literal notranslate"><span class="pre">-r</span></code>, and <code class="docutils literal notranslate"><span class="pre">-qq</span></code> options. <code class="docutils literal notranslate"><span class="pre">-q</span></code> option
was changed to a multilevel value. <code class="docutils literal notranslate"><span class="pre">-b</span></code> will always produce a
byte-code file ending in <code class="docutils literal notranslate"><span class="pre">.pyc</span></code>, never <code class="docutils literal notranslate"><span class="pre">.pyo</span></code>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7 版的變更: </span>新增選項 <code class="docutils literal notranslate"><span class="pre">--invalidation-mode</span></code>。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.9 版的變更: </span>Added the <code class="docutils literal notranslate"><span class="pre">-s</span></code>, <code class="docutils literal notranslate"><span class="pre">-p</span></code>, <code class="docutils literal notranslate"><span class="pre">-e</span></code> and <code class="docutils literal notranslate"><span class="pre">--hardlink-dupes</span></code> options.
Raised the default recursion limit from 10 to
<a class="reference internal" href="sys.html#sys.getrecursionlimit" title="sys.getrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code></a>.
Added the possibility to specify the <code class="docutils literal notranslate"><span class="pre">-o</span></code> option multiple times.</p>
</div>
<p>There is no command-line option to control the optimization level used by the
<a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> function, because the Python interpreter itself already
provides the option: <strong class="program">python -O -m compileall</strong>.</p>
<p>Similarly, the <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> function respects the <a class="reference internal" href="sys.html#sys.pycache_prefix" title="sys.pycache_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.pycache_prefix</span></code></a>
setting. The generated bytecode cache will only be useful if <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> is
run with the same <a class="reference internal" href="sys.html#sys.pycache_prefix" title="sys.pycache_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.pycache_prefix</span></code></a> (if any) that will be used at
runtime.</p>
</section>
<section id="public-functions">
<h2>Public functions<a class="headerlink" href="#public-functions" title="連結到這個標頭">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="compileall.compile_dir">
<span class="sig-prename descclassname"><span class="pre">compileall.</span></span><span class="sig-name descname"><span class="pre">compile_dir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dir</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxlevels</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">sys.getrecursionlimit()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ddir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quiet</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">legacy</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">optimize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">workers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">invalidation_mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">stripdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prependdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limit_sl_dest</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hardlink_dupes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#compileall.compile_dir" title="連結到這個定義">¶</a></dt>
<dd><p>Recursively descend the directory tree named by <em>dir</em>, compiling all <code class="file docutils literal notranslate"><span class="pre">.py</span></code>
files along the way. Return a true value if all the files compiled successfully,
and a false value otherwise.</p>
<p>The <em>maxlevels</em> parameter is used to limit the depth of the recursion; it
defaults to <code class="docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code>.</p>
<p>If <em>ddir</em> is given, it is prepended to the path to each file being compiled
for use in compilation time tracebacks, and is also compiled in to the
byte-code file, where it will be used in tracebacks and other messages in
cases where the source file does not exist at the time the byte-code file is
executed.</p>
<p>If <em>force</em> is true, modules are re-compiled even if the timestamps are up to
date.</p>
<p>If <em>rx</em> is given, its <code class="docutils literal notranslate"><span class="pre">search</span></code> method is called on the complete path to each
file considered for compilation, and if it returns a true value, the file
is skipped. This can be used to exclude files matching a regular expression,
given as a <a class="reference internal" href="re.html#re-objects"><span class="std std-ref">re.Pattern</span></a> object.</p>
<p>If <em>quiet</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code> (the default), the filenames and other
information are printed to standard out. Set to <code class="docutils literal notranslate"><span class="pre">1</span></code>, only errors are
printed. Set to <code class="docutils literal notranslate"><span class="pre">2</span></code>, all output is suppressed.</p>
<p>If <em>legacy</em> is true, byte-code files are written to their legacy locations
and names, which may overwrite byte-code files created by another version of
Python. The default is to write files to their <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a> locations and
names, which allows byte-code files from multiple versions of Python to
coexist.</p>
<p><em>optimize</em> specifies the optimization level for the compiler. It is passed to
the built-in <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> function. Accepts also a sequence of optimization
levels which lead to multiple compilations of one <code class="file docutils literal notranslate"><span class="pre">.py</span></code> file in one call.</p>
<p>The argument <em>workers</em> specifies how many workers are used to
compile files in parallel. The default is to not use multiple workers.
If the platform can't use multiple workers and <em>workers</em> argument is given,
then sequential compilation will be used as a fallback. If <em>workers</em>
is 0, the number of cores in the system is used. If <em>workers</em> is
lower than <code class="docutils literal notranslate"><span class="pre">0</span></code>, a <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> will be raised.</p>
<p><em>invalidation_mode</em> should be a member of the
<a class="reference internal" href="py_compile.html#py_compile.PycInvalidationMode" title="py_compile.PycInvalidationMode"><code class="xref py py-class docutils literal notranslate"><span class="pre">py_compile.PycInvalidationMode</span></code></a> enum and controls how the generated
pycs are invalidated at runtime.</p>
<p>The <em>stripdir</em>, <em>prependdir</em> and <em>limit_sl_dest</em> arguments correspond to
the <code class="docutils literal notranslate"><span class="pre">-s</span></code>, <code class="docutils literal notranslate"><span class="pre">-p</span></code> and <code class="docutils literal notranslate"><span class="pre">-e</span></code> options described above.
They may be specified as <code class="docutils literal notranslate"><span class="pre">str</span></code> or <a class="reference internal" href="os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a>.</p>
<p>If <em>hardlink_dupes</em> is true and two <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files with different optimization
level have the same content, use hard links to consolidate duplicate files.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版的變更: </span>新增 <em>legacy</em> 與 <em>optimize</em> 參數。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版的變更: </span>新增 <em>workers</em> 參數。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版的變更: </span><em>quiet</em> parameter was changed to a multilevel value.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版的變更: </span>The <em>legacy</em> parameter only writes out <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files, not <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files
no matter what the value of <em>optimize</em> is.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.6 版的變更: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7 版的變更: </span>新增 <em>invalidation_mode</em> 參數。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7.2 版的變更: </span>新增 <em>invalidation_mode</em> 參數的預設值被更新為 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.8 版的變更: </span>Setting <em>workers</em> to 0 now chooses the optimal number of cores.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.9 版的變更: </span>Added <em>stripdir</em>, <em>prependdir</em>, <em>limit_sl_dest</em> and <em>hardlink_dupes</em> arguments.
Default value of <em>maxlevels</em> was changed from <code class="docutils literal notranslate"><span class="pre">10</span></code> to <code class="docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code></p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="compileall.compile_file">
<span class="sig-prename descclassname"><span class="pre">compileall.</span></span><span class="sig-name descname"><span class="pre">compile_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fullname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ddir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quiet</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">legacy</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">optimize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">invalidation_mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">stripdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prependdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limit_sl_dest</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hardlink_dupes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#compileall.compile_file" title="連結到這個定義">¶</a></dt>
<dd><p>Compile the file with path <em>fullname</em>. Return a true value if the file
compiled successfully, and a false value otherwise.</p>
<p>If <em>ddir</em> is given, it is prepended to the path to the file being compiled
for use in compilation time tracebacks, and is also compiled in to the
byte-code file, where it will be used in tracebacks and other messages in
cases where the source file does not exist at the time the byte-code file is
executed.</p>
<p>If <em>rx</em> is given, its <code class="docutils literal notranslate"><span class="pre">search</span></code> method is passed the full path name to the
file being compiled, and if it returns a true value, the file is not
compiled and <code class="docutils literal notranslate"><span class="pre">True</span></code> is returned. This can be used to exclude files matching
a regular expression, given as a <a class="reference internal" href="re.html#re-objects"><span class="std std-ref">re.Pattern</span></a> object.</p>
<p>If <em>quiet</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code> (the default), the filenames and other
information are printed to standard out. Set to <code class="docutils literal notranslate"><span class="pre">1</span></code>, only errors are
printed. Set to <code class="docutils literal notranslate"><span class="pre">2</span></code>, all output is suppressed.</p>
<p>If <em>legacy</em> is true, byte-code files are written to their legacy locations
and names, which may overwrite byte-code files created by another version of
Python. The default is to write files to their <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a> locations and
names, which allows byte-code files from multiple versions of Python to
coexist.</p>
<p><em>optimize</em> specifies the optimization level for the compiler. It is passed to
the built-in <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> function. Accepts also a sequence of optimization
levels which lead to multiple compilations of one <code class="file docutils literal notranslate"><span class="pre">.py</span></code> file in one call.</p>
<p><em>invalidation_mode</em> should be a member of the
<a class="reference internal" href="py_compile.html#py_compile.PycInvalidationMode" title="py_compile.PycInvalidationMode"><code class="xref py py-class docutils literal notranslate"><span class="pre">py_compile.PycInvalidationMode</span></code></a> enum and controls how the generated
pycs are invalidated at runtime.</p>
<p>The <em>stripdir</em>, <em>prependdir</em> and <em>limit_sl_dest</em> arguments correspond to
the <code class="docutils literal notranslate"><span class="pre">-s</span></code>, <code class="docutils literal notranslate"><span class="pre">-p</span></code> and <code class="docutils literal notranslate"><span class="pre">-e</span></code> options described above.
They may be specified as <code class="docutils literal notranslate"><span class="pre">str</span></code> or <a class="reference internal" href="os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a>.</p>
<p>If <em>hardlink_dupes</em> is true and two <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files with different optimization
level have the same content, use hard links to consolidate duplicate files.</p>
<div class="versionadded">
<p><span class="versionmodified added">在 3.2 版被加入.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版的變更: </span><em>quiet</em> parameter was changed to a multilevel value.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版的變更: </span>The <em>legacy</em> parameter only writes out <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files, not <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files
no matter what the value of <em>optimize</em> is.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7 版的變更: </span>新增 <em>invalidation_mode</em> 參數。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7.2 版的變更: </span>新增 <em>invalidation_mode</em> 參數的預設值被更新為 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.9 版的變更: </span>Added <em>stripdir</em>, <em>prependdir</em>, <em>limit_sl_dest</em> and <em>hardlink_dupes</em> arguments.</p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="compileall.compile_path">
<span class="sig-prename descclassname"><span class="pre">compileall.</span></span><span class="sig-name descname"><span class="pre">compile_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">skip_curdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxlevels</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quiet</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">legacy</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">optimize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">invalidation_mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#compileall.compile_path" title="連結到這個定義">¶</a></dt>
<dd><p>Byte-compile all the <code class="file docutils literal notranslate"><span class="pre">.py</span></code> files found along <code class="docutils literal notranslate"><span class="pre">sys.path</span></code>. Return a
true value if all the files compiled successfully, and a false value otherwise.</p>
<p>If <em>skip_curdir</em> is true (the default), the current directory is not included
in the search. All other parameters are passed to the <a class="reference internal" href="#compileall.compile_dir" title="compileall.compile_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_dir()</span></code></a>
function. Note that unlike the other compile functions, <code class="docutils literal notranslate"><span class="pre">maxlevels</span></code>
defaults to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2 版的變更: </span>新增 <em>legacy</em> 與 <em>optimize</em> 參數。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版的變更: </span><em>quiet</em> parameter was changed to a multilevel value.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版的變更: </span>The <em>legacy</em> parameter only writes out <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files, not <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files
no matter what the value of <em>optimize</em> is.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7 版的變更: </span>新增 <em>invalidation_mode</em> 參數。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7.2 版的變更: </span>新增 <em>invalidation_mode</em> 參數的預設值被更新為 <code class="docutils literal notranslate"><span class="pre">None</span></code>。</p>
</div>
</dd></dl>
<p>To force a recompile of all the <code class="file docutils literal notranslate"><span class="pre">.py</span></code> files in the <code class="file docutils literal notranslate"><span class="pre">Lib/</span></code>
subdirectory and all its subdirectories:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">compileall</span>
<span class="n">compileall</span><span class="o">.</span><span class="n">compile_dir</span><span class="p">(</span><span class="s1">'Lib/'</span><span class="p">,</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="c1"># 執行相同的編譯,但排除 .svn 目錄中的檔案。</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">re</span>
<span class="n">compileall</span><span class="o">.</span><span class="n">compile_dir</span><span class="p">(</span><span class="s1">'Lib/'</span><span class="p">,</span> <span class="n">rx</span><span class="o">=</span><span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s1">'[/</span><span class="se">\\</span><span class="s1">][.]svn'</span><span class="p">),</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="c1"># pathlib.Path 物件也可以使用。</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">pathlib</span>
<span class="n">compileall</span><span class="o">.</span><span class="n">compile_dir</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">'Lib/'</span><span class="p">),</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">也參考</p>
<dl class="simple">
<dt><a class="reference internal" href="py_compile.html#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code></a> 模組</dt><dd><p>Byte-compile a single source file.</p>
</dd>
</dl>
</div>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">目錄</a></h3>
<ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> --- 位元組編譯 Python 函式庫</a><ul>
<li><a class="reference internal" href="#command-line-use">Command-line use</a></li>
<li><a class="reference internal" href="#public-functions">Public functions</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>上個主題</h4>
<p class="topless"><a href="py_compile.html"
title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> — 編譯 Python 來源檔案</a></p>
</div>
<div>
<h4>下個主題</h4>
<p class="topless"><a href="dis.html"
title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> --- Python bytecode 的反組譯器</a></p>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const title = document.querySelector('meta[property="og:title"]').content;
const elements = document.querySelectorAll('.improvepage');
const pageurl = window.location.href.split('?')[0];
elements.forEach(element => {
const url = new URL(element.href.split('?')[0].replace("-nojs", ""));
url.searchParams.set('pagetitle', title);
url.searchParams.set('pageurl', pageurl);
url.searchParams.set('pagesource', "library/compileall.rst");
element.href = url.toString();
});
});
</script>
<div role="note" aria-label="source link">
<h3>此頁面</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">回報錯誤</a></li>
<li><a class="improvepage" href="../improve-page-nojs.html">改進此頁面</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/library/compileall.rst?plain=1"
rel="nofollow">顯示原始碼
</a>
</li>
<li>
<a href="https://github.com/python/python-docs-zh-TW/blob/3.14/library/compileall.po?plain=1"
rel="nofollow">顯示翻譯原始碼</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="收合側邊欄">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<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="dis.html" title="dis --- Python bytecode 的反組譯器"
>下一頁</a> |</li>
<li class="right" >
<a href="py_compile.html" title="py_compile — 編譯 Python 來源檔案"
>上一頁</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.14.5 Documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python 標準函式庫 (Standard Library)</a> »</li>
<li class="nav-item nav-item-2"><a href="language.html" >Python 語言服務</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> --- 位元組編譯 Python 函式庫</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="search" name="q" id="search-box">
<input type="submit" value="前往">
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
主題
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>自動</option>
<option value="light">淺色模式</option>
<option value="dark">深色模式</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">版權所有</a> 2001 Python Software Foundation.
<br>
此頁面採用 Python 軟體基金會授權條款第 2 版。
<br>
文件中的範例、應用技巧與其他程式碼額外採用了 Zero Clause BSD 授權條款。
<br>
更多訊息請見<a href="/license.html">歷史與授權條款</a>。<br>
<br>
Python 軟體基金會是一家非營利法人。
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
<br>
<br>
最後更新於 5月 14, 2026 (19:12 UTC)。
<a href="/bugs.html">發現 bug</a>?
<br>
以 <a href="https://www.sphinx-doc.org/">Sphinx</a>8.2.3建立。
</div>
</body>
</html>