|
18 | 18 | it is also checked for site-packages (sys.base_prefix and |
19 | 19 | sys.base_exec_prefix will always be the "real" prefixes of the Python |
20 | 20 | installation). If "pyvenv.cfg" (a bootstrap configuration file) contains |
21 | | -the key "include-system-site-packages" is set to "true" |
22 | | -(case-insensitive), the system-level prefixes will still also be |
23 | | -searched for site-packages; otherwise they won't. If the system-level |
24 | | -prefixes are not included then the user site prefixes are also implicitly |
25 | | -not searched for site-packages. |
26 | | -
|
27 | | -All of the resulting site-specific directories, if they exist, are |
28 | | -appended to sys.path, and also inspected for path configuration |
29 | | -files. |
30 | | -
|
31 | | -A path configuration file is a file whose name has the form |
32 | | -<package>.pth; its contents are additional directories (one per line) |
33 | | -to be added to sys.path. Non-existing directories (or |
34 | | -non-directories) are never added to sys.path; no directory is added to |
35 | | -sys.path more than once. Blank lines and lines beginning with |
36 | | -'#' are skipped. Lines starting with 'import' are executed. |
37 | | -
|
38 | | -For example, suppose sys.prefix and sys.exec_prefix are set to |
39 | | -/usr/local and there is a directory /usr/local/lib/python2.5/site-packages |
40 | | -with three subdirectories, foo, bar and spam, and two path |
41 | | -configuration files, foo.pth and bar.pth. Assume foo.pth contains the |
42 | | -following: |
43 | | -
|
44 | | - # foo package configuration |
45 | | - foo |
46 | | - bar |
47 | | - bletch |
48 | | -
|
49 | | -and bar.pth contains: |
50 | | -
|
51 | | - # bar package configuration |
52 | | - bar |
53 | | -
|
54 | | -Then the following directories are added to sys.path, in this order: |
55 | | -
|
56 | | - /usr/local/lib/python2.5/site-packages/bar |
57 | | - /usr/local/lib/python2.5/site-packages/foo |
58 | | -
|
59 | | -Note that bletch is omitted because it doesn't exist; bar precedes foo |
60 | | -because bar.pth comes alphabetically before foo.pth; and spam is |
61 | | -omitted because it is not mentioned in either path configuration file. |
62 | | -
|
63 | | -The readline module is also automatically configured to enable |
64 | | -completion for systems that support it. This can be overridden in |
65 | | -sitecustomize, usercustomize or PYTHONSTARTUP. Starting Python in |
66 | | -isolated mode (-I) disables automatic readline configuration. |
67 | | -
|
68 | | -After these operations, an attempt is made to import a module |
69 | | -named sitecustomize, which can perform arbitrary additional |
70 | | -site-specific customizations. If this import fails with an |
71 | | -ImportError exception, it is silently ignored. |
| 21 | +the key "include-system-site-packages" set to "true" (case-insensitive), |
| 22 | +the system-level prefixes will still also be searched for site-packages; |
| 23 | +otherwise they won't. |
| 24 | +
|
| 25 | +Two kinds of configuration files are processed in each site-packages |
| 26 | +directory: |
| 27 | +
|
| 28 | +- <name>.pth files extend sys.path with additional directories (one per |
| 29 | + line). Lines starting with "import" are deprecated (see PEP 829). |
| 30 | +
|
| 31 | +- <name>.start files specify startup entry points using the |
| 32 | + pkg.mod:callable syntax. These are resolved via pkgutil.resolve_name() |
| 33 | + and called with no arguments. |
| 34 | +
|
| 35 | +All .pth path extensions are applied before any .start entry points are |
| 36 | +executed, ensuring that paths are available before startup code runs. |
| 37 | +
|
| 38 | +See the documentation for the site module for full details: |
| 39 | +https://docs.python.org/3/library/site.html |
72 | 40 | """ |
73 | 41 |
|
74 | 42 | import sys |
|
0 commit comments