http

http.server.BaseHTTPRequestHandler now buffers the headers and writes them all at once when end_headers() is called. A new method flush_headers() can be used to directly manage when the accumulated headers are sent. (Contributed by Andrew Schaaf in bpo-3709 [https://bugs.python.org/issue?@action=redirect&bpo=3709].) http.server now produces valid HTML 4.01 strict output. (Contributed by Ezio Melotti in bpo-13295 [https://bugs.python.org/issue?@action=redirect&bpo=13295].) http.client.HTTPResponse now has a readinto() method, which means it can be used as an io.RawIOBase class. (Contributed by John Kuhn in bpo-13464 [https://bugs.python.org/issue?@action=redirect&bpo=13464].)

html

html.parser.HTMLParser is now able to parse broken markup without raising errors, therefore the strict argument of the constructor and the HTMLParseError exception are now deprecated. The ability to parse broken markup is the result of a number of bug fixes that are also available on the latest bug fix releases of Python 2.7/3.2. (Contributed by Ezio Melotti in bpo-15114 [https://bugs.python.org/issue?@action=redirect&bpo=15114], and bpo-14538 [https://bugs.python.org/issue?@action=redirect&bpo=14538], bpo-13993 [https://bugs.python.org/issue?@action=redirect&bpo=13993], bpo-13960 [https://bugs.python.org/issue?@action=redirect&bpo=13960], bpo-13358 [https://bugs.python.org/issue?@action=redirect&bpo=13358], bpo-1745761 [https://bugs.python.org/issue?@action=redirect&bpo=1745761], bpo-755670 [https://bugs.python.org/issue?@action=redirect&bpo=755670], bpo-13357 [https://bugs.python.org/issue?@action=redirect&bpo=13357], bpo-12629 [https://bugs.python.org/issue?@action=redirect&bpo=12629], bpo-1200313 [https://bugs.python.org/issue?@action=redirect&bpo=1200313], bpo-670664 [https://bugs.python.org/issue?@action=redirect&bpo=670664], bpo-13273 [https://bugs.python.org/issue?@action=redirect&bpo=13273], bpo-12888 [https://bugs.python.org/issue?@action=redirect&bpo=12888], bpo-7311 [https://bugs.python.org/issue?@action=redirect&bpo=7311].) A new html5 dictionary that maps HTML5 named character references to the equivalent Unicode character(s) (e.g. html5['gt;'] == '>') has been added to the html.entities module. The dictionary is now also used by HTMLParser. (Contributed by Ezio Melotti in bpo-11113 [https://bugs.python.org/issue?@action=redirect&bpo=11113] and bpo-15156 [https://bugs.python.org/issue?@action=redirect&bpo=15156].)

imaplib

The IMAP4_SSL constructor now accepts an SSLContext parameter to control parameters of the secure channel.

(由 Sijin Joseph 在 bpo-8808 [https://bugs.python.org/issue?@action=redirect&bpo=8808] 中贡献。)

inspect

A new getclosurevars() function has been added. This function reports the current binding of all names referenced from the function body and where those names were resolved, making it easier to verify correct internal state when testing code that relies on stateful closures.

(由 Meador Inge 和 Nick Coghlan 在 bpo-13062 [https://bugs.python.org/issue?@action=redirect&bpo=13062] 中贡献。)

A new getgeneratorlocals() function has been added. This function reports the current binding of local variables in the generator's stack frame, making it easier to verify correct internal state when testing generators.

(由 Meador Inge 在 bpo-15153 [https://bugs.python.org/issue?@action=redirect&bpo=15153] 中贡献。)

io

The open() function has a new 'x' mode that can be used to exclusively create a new file, and raise a FileExistsError if the file already exists. It is based on the C11 'x' mode to fopen().

(由 David Townshend 在 bpo-12760 [https://bugs.python.org/issue?@action=redirect&bpo=12760] 中贡献。)

The constructor of the TextIOWrapper class has a new write_through optional argument. If write_through is True, calls to write() are guaranteed not to be buffered: any data written on the TextIOWrapper object is immediately handled to its underlying binary buffer.

itertools

accumulate() now takes an optional func argument for providing a user-supplied binary function.

logging

The basicConfig() function now supports an optional handlers argument taking an iterable of handlers to be added to the root logger.

A class level attribute append_nul has been added to SysLogHandler to allow control of the appending of the NUL (\000) byte to syslog records, since for some daemons it is required while for others it is passed through to the log.

math

The math module has a new function, log2(), which returns the base-2 logarithm of x.

(Written by Mark Dickinson in bpo-11888 [https://bugs.python.org/issue?@action=redirect&bpo=11888].)

mmap

The read() method is now more compatible with other file-like objects: if the argument is omitted or specified as None, it returns the bytes from the current file position to the end of the mapping. (Contributed by Petri Lehtinen in bpo-12021 [https://bugs.python.org/issue?@action=redirect&bpo=12021].)

multiprocessing

The new multiprocessing.connection.wait() function allows polling multiple objects (such as connections, sockets and pipes) with a timeout. (Contributed by Richard Oudkerk in bpo-12328 [https://bugs.python.org/issue?@action=redirect&bpo=12328].) multiprocessing.Connection objects can now be transferred over multiprocessing connections. (Contributed by Richard Oudkerk in bpo-4892 [https://bugs.python.org/issue?@action=redirect&bpo=4892].) multiprocessing.Process now accepts a daemon keyword argument to override the default behavior of inheriting the daemon flag from the parent process (bpo-6064 [https://bugs.python.org/issue?@action=redirect&bpo=6064]).

New attribute multiprocessing.Process.sentinel allows a program to wait on multiple Process objects at one time using the appropriate OS primitives (for example, select on posix systems).

New methods multiprocessing.pool.Pool.starmap() and starmap_async() provide itertools.starmap() equivalents to the existing multiprocessing.pool.Pool.map() and map_async() functions. (Contributed by Hynek Schlawack in bpo-12708 [https://bugs.python.org/issue?@action=redirect&bpo=12708].)

nntplib

The nntplib.NNTP class now supports the context management protocol to unconditionally consume socket.error exceptions and to close the NNTP connection when done:

  1. >>> from nntplib import NNTP
  2. >>> with NNTP('news.gmane.org') as n:
  3. ... n.group('gmane.comp.python.committers')
  4. ...
  5. ('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers')
  6. >>>

(由 Giampaolo Rodolà 在 bpo-9795 [https://bugs.python.org/issue?@action=redirect&bpo=9795] 中贡献。)

os

  • The os module has a new pipe2() function that makes it possible to create a pipe with O_CLOEXEC or O_NONBLOCK flags set atomically. This is especially useful to avoid race conditions in multi-threaded programs.

  • The os module has a new sendfile() function which provides an efficient "zero-copy" way for copying data from one file (or socket) descriptor to another. The phrase "zero-copy" refers to the fact that all of the copying of data between the two descriptors is done entirely by the kernel, with no copying of data into userspace buffers. sendfile() can be used to efficiently copy data from a file on disk to a network socket, e.g. for downloading a file.

(Patch submitted by Ross Lagerwall and Giampaolo Rodolà in bpo-10882 [https://bugs.python.org/issue?@action=redirect&bpo=10882].)

(Patch submitted by Giampaolo Rodolà in bpo-10784 [https://bugs.python.org/issue?@action=redirect&bpo=10784].)

pdb

Tab-completion is now available not only for command names, but also their arguments. For example, for the break command, function and file names are completed.

(由 Georg Brandl 在 bpo-14210 [https://bugs.python.org/issue?@action=redirect&bpo=14210] 中贡献)

pickle

pickle.Pickler objects now have an optional dispatch_table attribute allowing per-pickler reduction functions to be set.

(由 Richard Oudkerk 在 bpo-14166 [https://bugs.python.org/issue?@action=redirect&bpo=14166] 中贡献。)

pydoc

The Tk GUI and the serve() function have been removed from the pydoc module: pydoc -g and serve() have been deprecated in Python 3.2.

re

str regular expressions now support \u and \U escapes.

(由 Serhiy Storchaka 在 bpo-3665 [https://bugs.python.org/issue?@action=redirect&bpo=3665] 中贡献。)

sched

select

Solaris and derivative platforms have a new class select.devpoll for high performance asynchronous sockets via devpoll. (Contributed by Jesús Cea Avión in bpo-6397 [https://bugs.python.org/issue?@action=redirect&bpo=6397].)

shlex

The previously undocumented helper function quote from the pipes modules has been moved to the shlex module and documented. quote() properly escapes all characters in a string that might be otherwise given special meaning by the shell.

shutil

signal

smtpd

The smtpd module now supports RFC 5321 [https://datatracker.ietf.org/doc/html/rfc5321.html] (extended SMTP) and RFC 1870 [https://datatracker.ietf.org/doc/html/rfc1870.html] (size extension). Per the standard, these extensions are enabled if and only if the client initiates the session with an EHLO command.

(Initial ELHO support by Alberto Trevino. Size extension by Juhana Jauhiainen. Substantial additional work on the patch contributed by Michele Orrù and Dan Boswell. bpo-8739 [https://bugs.python.org/issue?@action=redirect&bpo=8739])

smtplib

The SMTP, SMTP_SSL, and LMTP classes now accept a source_address keyword argument to specify the (host, port) to use as the source address in the bind call when creating the outgoing socket. (Contributed by Paulo Scardine in bpo-11281 [https://bugs.python.org/issue?@action=redirect&bpo=11281].) SMTP now supports the context management protocol, allowing an SMTP instance to be used in a with statement. (Contributed by Giampaolo Rodolà in bpo-11289 [https://bugs.python.org/issue?@action=redirect&bpo=11289].) The SMTP_SSL constructor and the starttls() method now accept an SSLContext parameter to control parameters of the secure channel. (Contributed by Kasun Herath in bpo-8809 [https://bugs.python.org/issue?@action=redirect&bpo=8809].)

socket

(Contributed by David Watson in bpo-6560 [https://bugs.python.org/issue?@action=redirect&bpo=6560], based on an earlier patch by Heiko Wundram)

(Contributed by Matthias Fuchs, updated by Tiago Gonçalves in bpo-10141 [https://bugs.python.org/issue?@action=redirect&bpo=10141].)

socketserver

BaseServer now has an overridable method service_actions() that is called by the serve_forever() method in the service loop. ForkingMixIn now uses this to clean up zombie child processes. (Contributed by Justin Warkentin in bpo-11109 [https://bugs.python.org/issue?@action=redirect&bpo=11109].)

sqlite3

New sqlite3.Connection method set_trace_callback() can be used to capture a trace of all sql commands processed by sqlite. (Contributed by Torsten Landschoff in bpo-11688 [https://bugs.python.org/issue?@action=redirect&bpo=11688].)

ssl

  • The ssl module has two new random generation functions:

    • RAND_bytes(): generate cryptographically strong pseudo-random bytes.

    • RAND_pseudo_bytes(): 生成伪随机字节。

(由 Victor Stinner 在 bpo-12049 [https://bugs.python.org/issue?@action=redirect&bpo=12049] 中贡献。)

stat

The undocumented tarfile.filemode function has been moved to stat.filemode(). It can be used to convert a file's mode to a string of the form '-rwxrwxrwx'.

(由 Giampaolo Rodolà 在 bpo-14807 [https://bugs.python.org/issue?@action=redirect&bpo=14807] 中贡献。)

struct

The struct module now supports ssize_t and size_t via the new codes n and N, respectively. (Contributed by Antoine Pitrou in bpo-3163 [https://bugs.python.org/issue?@action=redirect&bpo=3163].)

subprocess

Command strings can now be bytes objects on posix platforms. (Contributed by Victor Stinner in bpo-8513 [https://bugs.python.org/issue?@action=redirect&bpo=8513].) A new constant DEVNULL allows suppressing output in a platform-independent fashion. (Contributed by Ross Lagerwall in bpo-5870 [https://bugs.python.org/issue?@action=redirect&bpo=5870].)

sys

The sys module has a new thread_info named tuple holding information about the thread implementation (bpo-11223 [https://bugs.python.org/issue?@action=redirect&bpo=11223]).

tarfile

tarfile now supports lzma encoding via the lzma module. (Contributed by Lars Gustäbel in bpo-5689 [https://bugs.python.org/issue?@action=redirect&bpo=5689].)

tempfile

tempfile.SpooledTemporaryFile's truncate() method now accepts a size parameter. (Contributed by Ryan Kelly in bpo-9957 [https://bugs.python.org/issue?@action=redirect&bpo=9957].)

textwrap

The textwrap module has a new indent() that makes it straightforward to add a common prefix to selected lines in a block of text (bpo-13857 [https://bugs.python.org/issue?@action=redirect&bpo=13857]).

threading

threading.Condition, threading.Semaphore, threading.BoundedSemaphore, threading.Event, and threading.Timer, all of which used to be factory functions returning a class instance, are now classes and may be subclassed. (Contributed by Éric Araujo in bpo-10968 [https://bugs.python.org/issue?@action=redirect&bpo=10968].) The threading.Thread constructor now accepts a daemon keyword argument to override the default behavior of inheriting the daemon flag value from the parent thread (bpo-6064 [https://bugs.python.org/issue?@action=redirect&bpo=6064]).

The formerly private function thread.getident is now available as the public function threading.get_ident(). This eliminates several cases of direct access to the _thread module in the stdlib. Third party code that used thread.getident should likewise be changed to use the new public interface.

time

The PEP 418 [https://peps.python.org/pep-0418/] added new functions to the time module:

  • get_clock_info(): Get information on a clock.

  • monotonic(): Monotonic clock (cannot go backward), not affected by system clock updates.

  • perf_counter(): Performance counter with the highest available resolution to measure a short duration.

  • process_time(): Sum of the system and user CPU time of the current process.

Other new functions:

To improve cross platform consistency, sleep() now raises a ValueError when passed a negative sleep value. Previously this was an error on posix, but produced an infinite sleep on Windows.

types

Add a new types.MappingProxyType class: Read-only proxy of a mapping. (bpo-14386 [https://bugs.python.org/issue?@action=redirect&bpo=14386]) The new functions types.new_class() and types.prepare_class() provide support for PEP 3115 [https://peps.python.org/pep-3115/] compliant dynamic type creation. (bpo-14588 [https://bugs.python.org/issue?@action=redirect&bpo=14588])

unittest

assertRaises(), assertRaisesRegex(), assertWarns(), and assertWarnsRegex() now accept a keyword argument msg when used as context managers. (Contributed by Ezio Melotti and Winston Ewert in bpo-10775 [https://bugs.python.org/issue?@action=redirect&bpo=10775].) unittest.TestCase.run() now returns the TestResult object.

urllib

The Request class, now accepts a method argument used by get_method() to determine what HTTP method should be used. For example, this will send a 'HEAD' request:

  1. >>> urlopen(Request('https://www.python.org', method='HEAD'))

(bpo-1673007 [https://bugs.python.org/issue?@action=redirect&bpo=1673007])

webbrowser

The webbrowser module supports more "browsers": Google Chrome (named chrome, chromium, chrome-browser or chromium-browser depending on the version and operating system), and the generic launchers xdg-open, from the FreeDesktop.org project, and gvfs-open, which is the default URI handler for GNOME 3. (The former contributed by Arnaud Calmettes in bpo-13620 [https://bugs.python.org/issue?@action=redirect&bpo=13620], the latter by Matthias Klose in bpo-14493 [https://bugs.python.org/issue?@action=redirect&bpo=14493].)

xml.etree.ElementTree

The xml.etree.ElementTree module now imports its C accelerator by default; there is no longer a need to explicitly import xml.etree.cElementTree (this module stays for backwards compatibility, but is now deprecated). In addition, the iter family of methods of Element has been optimized (rewritten in C). The module's documentation has also been greatly improved with added examples and a more detailed reference.

zlib

New attribute zlib.Decompress.eof makes it possible to distinguish between a properly formed compressed stream and an incomplete or truncated one. (Contributed by Nadeem Vawda in bpo-12646 [https://bugs.python.org/issue?@action=redirect&bpo=12646].) New attribute zlib.ZLIB_RUNTIME_VERSION reports the version string of the underlying zlib library that is loaded at runtime. (Contributed by Torsten Landschoff in bpo-12306 [https://bugs.python.org/issue?@action=redirect&bpo=12306].)

性能优化

已增加的主要性能改善:

  • 得益于:pep:393 ,Unicode 字符串的某些操作已得到优化:

    • the memory footprint is divided by 2 to 4 depending on the text

    • 将 ASCII 字符串编码为 UTF-8 不再需要对字符进行编码,UTF-8 的表示法与 ASCII 的表示法是共享的

    • the UTF-8 encoder has been optimized

    • repeating a single ASCII letter and getting a substring of an ASCII string is 4 times faster

  • UTF-8 编码现在快 2 到 4 倍。 UTF-16 编码的速度现在提高了 10 倍。

(由 Serhiy Storchaka 在 bpo-14624 [https://bugs.python.org/issue?@action=redirect&bpo=14624], bpo-14738 [https://bugs.python.org/issue?@action=redirect&bpo=14738] 和 bpo-15026 [https://bugs.python.org/issue?@action=redirect&bpo=15026] 中贡献)。

构建和 C API 的改变

针对 Python 构建过程和 C API 的改变包括:

弃用

不支持的操作系统

由于缺少维护人员,不再支持 OS/2 和 VMS 系统 。

由于维护负担,将 COMSPEC 设置为 command.com 的 Windows平台(含Windows 2000)不再受支持。

OSF支持在3.2中被弃用,现在已经被完全删除。

已弃用的 Python 模块、函数和方法

已弃用的 C API 函数和类型

Py_UNICODE 已经在 PEP 393 [https://peps.python.org/pep-0393/] 弃用,并将于 Python 4 中移除。所有使用此类型的函数都已弃用:

Unicode functions and methods using Py_UNICODE and Py_UNICODE* types:

Functions and macros manipulating Py_UNICODE* strings:

编码器:

弃用的功能

array 模块的'u' 格式代码现已弃用,将在 Python 4 中与 (Py_UNICODE) API 的其他部分一起删除。

移植到 Python 3.3

本节列出了先前描述的更改以及可能需要更改代码的其他错误修正.

移植 Python 代码

  • 默认启用哈希随机化。 将 PYTHONHASHSEED 环境变量设为 0 可禁用哈希随机化。 另请参阅 object.__hash__() 方法。

  • bpo-12326 [https://bugs.python.org/issue?@action=redirect&bpo=12326]: 在 Linux 上,sys.platform 不再包含主要版本。现在它始终是 "linux",而不是 "linux2" 或 "linux3",这取决于用于构建 Python 的 Linux 版本。请用 sys.platform.startswith('linux') 替换 sys.platform == 'linux2',如果不需要支持较旧的 Python 版本,则可直接替换成 sys.platform == 'linux'。

  • bpo-13847 [https://bugs.python.org/issue?@action=redirect&bpo=13847], bpo-14180 [https://bugs.python.org/issue?@action=redirect&bpo=14180]: timedatetime: 现在如果时间戳超出范围将会引发 OverflowError 而不是 ValueError。 现在如果 C 函数 gmtime()localtime() 失败 将会引发 OSError

  • The default finders used by import now utilize a cache of what is contained within a specific directory. If you create a Python source file or sourceless bytecode file, make sure to call importlib.invalidate_caches() to clear out the cache for the finders to notice the new file.

  • ImportError now uses the full name of the module that was attempted to be imported. Doctests that check ImportErrors' message will need to be updated to use the full name of the module instead of just the tail of the name.

  • The index argument to __import__() now defaults to 0 instead of -1 and no longer support negative values. It was an oversight when PEP 328 [https://peps.python.org/pep-0328/] was implemented that the default value remained -1. If you need to continue to perform a relative import followed by an absolute import, then perform the relative import using an index of 1, followed by another import using an index of 0. It is preferred, though, that you use importlib.import_module() rather than call __import__() directly.

  • __import__() no longer allows one to use an index value other than 0 for top-level modules. E.g. __import__('sys', level=1) is now an error.

  • Because sys.meta_path and sys.path_hooks now have finders on them by default, you will most likely want to use list.insert() instead of list.append() to add to those lists.

  • Because None is now inserted into sys.path_importer_cache, if you are clearing out entries in the dictionary of paths that do not have a finder, you will need to remove keys paired with values of None and imp.NullImporter to be backwards-compatible. This will lead to extra overhead on older versions of Python that re-insert None into sys.path_importer_cache where it represents the use of implicit finders, but semantically it should not change anything.

  • importlib.abc.Finder no longer specifies a find_module() abstract method that must be implemented. If you were relying on subclasses to implement that method, make sure to check for the method's existence first. You will probably want to check for find_loader() first, though, in the case of working with path entry finders.

  • pkgutil has been converted to use importlib internally. This eliminates many edge cases where the old behaviour of the PEP 302 [https://peps.python.org/pep-0302/] import emulation failed to match the behaviour of the real import system. The import emulation itself is still present, but is now deprecated. The pkgutil.iter_importers() and pkgutil.walk_packages() functions special case the standard import hooks so they are still supported even though they do not provide the non-standard iter_modules() method.

  • A longstanding RFC-compliance bug (bpo-1079 [https://bugs.python.org/issue?@action=redirect&bpo=1079]) in the parsing done by email.header.decode_header() has been fixed. Code that uses the standard idiom to convert encoded headers into unicode (str(make_header(decode_header(h))) will see no change, but code that looks at the individual tuples returned by decode_header will see that whitespace that precedes or follows ASCII sections is now included in the ASCII section. Code that builds headers using make_header should also continue to work without change, since make_header continues to add whitespace between ASCII and non-ASCII sections if it is not already present in the input strings.

  • email.utils.formataddr() now does the correct content transfer encoding when passed non-ASCII display names. Any code that depended on the previous buggy behavior that preserved the non-ASCII unicode in the formatted output string will need to be changed (bpo-1690608 [https://bugs.python.org/issue?@action=redirect&bpo=1690608]).

  • poplib.POP3.quit() may now raise protocol errors like all other poplib methods. Code that assumes quit does not raise poplib.error_proto errors may need to be changed if errors on quit are encountered by a particular application (bpo-11291 [https://bugs.python.org/issue?@action=redirect&bpo=11291]).

  • The strict argument to email.parser.Parser, deprecated since Python 2.4, has finally been removed.

  • The deprecated method unittest.TestCase.assertSameElements has been removed.

  • The deprecated variable time.accept2dyear has been removed.

  • 被弃用的 Context._clamp 属性已从 decimal 模块中移除。 在此之前它已被公有属性 clamp 取代。 (参见 bpo-8540 [https://bugs.python.org/issue?@action=redirect&bpo=8540]。)

  • The undocumented internal helper class SSLFakeFile has been removed from smtplib, since its functionality has long been provided directly by socket.socket.makefile().

  • Passing a negative value to time.sleep() on Windows now raises an error instead of sleeping forever. It has always raised an error on posix.

  • The ast.__version__ constant has been removed. If you need to make decisions affected by the AST version, use sys.version_info to make the decision.

  • Code that used to work around the fact that the threading module used factory functions by subclassing the private classes will need to change to subclass the now-public classes.

  • The undocumented debugging machinery in the threading module has been removed, simplifying the code. This should have no effect on production code, but is mentioned here in case any application debug frameworks were interacting with it (bpo-13550 [https://bugs.python.org/issue?@action=redirect&bpo=13550]).

移植 C 代码

  • In the course of changes to the buffer API the undocumented smalltable member of the Py_buffer structure has been removed and the layout of the PyMemoryViewObject has changed.

All extensions relying on the relevant parts in memoryobject.h or object.h must be rebuilt.

  • Due to PEP 393, the Py_UNICODE type and all functions using this type are deprecated (but will stay available for at least five years). If you were using low-level Unicode APIs to construct and access unicode objects and you want to benefit of the memory footprint reduction provided by PEP 393 [https://peps.python.org/pep-0393/], you have to convert your code to the new Unicode API.

However, if you only have been using high-level functions such as PyUnicode_Concat(), PyUnicode_Join() or PyUnicode_FromFormat(), your code will automatically take advantage of the new unicode representations.

Building C extensions

  • The range of possible file names for C extensions has been narrowed. Very rarely used spellings have been suppressed: under POSIX, files named xxxmodule.so, xxxmodule.abi3.so and xxxmodule.cpython-*.so are no longer recognized as implementing the xxx module. If you had been generating such files, you have to switch to the other spellings (i.e., remove the module string from the file names).

(在 bpo-14040 [https://bugs.python.org/issue?@action=redirect&bpo=14040] 中实现。)

命令行开关的变化

  • 删除了 -Q命令-line旗标 和相关工具。 检查 sys.flags.division_warning 的代码需要更新。

bpo-10998 [https://bugs.python.org/issue?@action=redirect&bpo=10998],由 Éric Araujo 贡献。)

  • 当 python 附带 -S 启动时,import site 将不再向模块搜索路径添加 site 专属路径。 在之前版本中则会这样做。

(由 Carl Meyer 在 bpo-11591 [https://bugs.python.org/issue?@action=redirect&bpo=11591] 中贡献并由 Éric Araujo 进行修改。)