distutilsBuilding and installing Python modules构建和安装Python模块


distutils is deprecated with removal planned for Python 3.12. 已弃用,计划在Python 3.12中删除。See the What’s New entry for more information.有关详细信息,请参阅新增功能条目。


The distutils package provides support for building and installing additional modules into a Python installation. distutils包支持在Python安装中构建和安装其他模块。The new modules may be either 100%-pure Python, or may be extension modules written in C, or may be collections of Python packages which include modules coded in both Python and C.新模块可以是100%纯Python,也可以是用C编写的扩展模块,或者可以是Python包的集合,其中包括用Python和C编码的模块。

Most Python users will not want to use this module directly, but instead use the cross-version tools maintained by the Python Packaging Authority. 大多数Python用户不想直接使用这个模块,而是使用Python打包管理局维护的跨版本工具。In particular, setuptools is an enhanced alternative to distutils that provides:特别是,setuptoolsdistutils的一种增强型替代方案,它提供:

  • support for declaring project dependencies支持声明项目依赖项

  • additional mechanisms for configuring which files to include in source releases (including plugins for integration with version control systems)用于配置要包含在源版本中的文件的附加机制(包括用于与版本控制系统集成的插件)

  • the ability to declare project “entry points”, which can be used as the basis for application plugin systems声明项目“入口点”的能力,可以用作应用程序插件系统的基础

  • the ability to automatically generate Windows command line executables at installation time rather than needing to prebuild them能够在安装时自动生成Windows命令行可执行文件,而不需要预先生成它们

  • consistent behaviour across all supported Python versions所有支持的Python版本的一致行为

The recommended pip installer runs all setup.py scripts with setuptools, even if the script itself only imports distutils. 推荐的pip安装程序使用setuptools运行所有setup.py脚本,即使脚本本身只导入distutilsRefer to the Python Packaging User Guide for more information.有关更多信息,请参阅Python打包用户指南

For the benefits of packaging tool authors and users seeking a deeper understanding of the details of the current packaging and distribution system, the legacy distutils based user documentation and API reference remain available:为了让打包工具的作者和用户更深入地了解当前打包和分发系统的细节,仍然可以使用基于distutils的遗留用户文档和API参考: