4. 在 Windows 使用 Python

This document aims to give an overview of Windows-specific behaviour you should know about when using Python on Microsoft Windows.

Unlike most Unix systems and services, Windows does not include a system supported installation of Python. To make Python available, the CPython team has compiled Windows installers with every release for many years. These installers are primarily intended to add a per-user installation of Python, with the core interpreter and library being used by a single user. The installer is also able to install for all users of a single machine, and a separate ZIP file is available for application-local distributions.

As specified in PEP 11 , a Python release only supports a Windows platform while Microsoft considers the platform under extended support. This means that Python 3.13 supports Windows 8.1 and newer. If you require Windows 7 support, please install Python 3.8.

There are a number of different installers available for Windows, each with certain benefits and downsides.

完整安装程序 contains all components and is the best option for developers using Python for any kind of project.

The Microsoft Store package is a simple installation of Python that is suitable for running scripts and packages, and using IDLE or other development environments. It requires Windows 10 and above, but can be safely installed without corrupting other programs. It also provides many convenient commands for launching Python and its tools.

nuget.org 包 are lightweight installations intended for continuous integration systems. It can be used to build Python packages or run scripts, but is not updateable and has no user interface tools.

可嵌入包 is a minimal package of Python suitable for embedding into a larger application.

4.1. 完整安装程序

4.1.1. 安装步骤

Four Python 3.13 installers are available for download - two each for the 32-bit and 64-bit versions of the interpreter. The web installer is a small initial download, and it will automatically download the required components as necessary. The 离线安装程序 includes the components necessary for a default installation and only requires an internet connection for optional features. See 安装无需下载 for other ways to avoid downloading during installation.

After starting the installer, one of two options may be selected:

../_images/win_installer.png

If you select “Install Now”:

  • You will not need to be an administrator (unless a system update for the C Runtime Library is required or you install the 用于 Windows 的 Python 启动器 for all users)

  • Python will be installed into your user directory

  • The 用于 Windows 的 Python 启动器 will be installed according to the option at the bottom of the first page

  • The standard library, test suite, launcher and pip will be installed

  • If selected, the install directory will be added to your PATH

  • Shortcuts will only be visible for the current user

Selecting “Customize installation” will allow you to select the features to install, the installation location and other options or post-install actions. To install debugging symbols or binaries, you will need to use this option.

To perform an all-users installation, you should select “Customize installation”. In this case:

  • You may be required to provide administrative credentials or approval

  • Python will be installed into the Program Files directory

  • The 用于 Windows 的 Python 启动器 will be installed into the Windows directory

  • Optional features may be selected during installation

  • The standard library can be pre-compiled to bytecode

  • If selected, the install directory will be added to the system PATH

  • Shortcuts are available for all users

4.1.2. 移除 MAX_PATH 限制

Windows historically has limited path lengths to 260 characters. This meant that paths longer than this would not resolve and errors would result.

In the latest versions of Windows, this limitation can be expanded to approximately 32,000 characters. Your administrator will need to activate the “Enable Win32 long paths” group policy, or set LongPathsEnabled to 1 in the registry key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem .

This allows the open() 函数, os module and most other path functionality to accept and return paths longer than 260 characters.

After changing the above option, no further configuration is required.

3.6 版改变: Support for long paths was enabled in Python.