Skip to Content
Python高级编程(第2版)
book

Python高级编程(第2版)

by Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
February 2024
Intermediate to advanced
423 pages
6h 9m
Chinese
Packt Publishing
Content preview from Python高级编程(第2版)

第5章 编写一个包

本章重点介绍编写并发布Python包的可重复过程。其目的是:

  • 在开始实际工作之前,缩短设置所有内容所需要的时间。
  • 提供编写包的标准化方法。
  • 简化测试驱动开发方法的使用。
  • 使发布过程更加简单。

本章包括以下4部分内容:

  • 所有包的通用模式(common pattern),描述所有Python包之间的相似之处,以及distutils和setuptools如何发挥核心作用。
  • 什么是命名空间包(namespace packages),以及它为什么有用。
  • 在Python包索引(Python Package Index,PyPI)中如何注册并上传包,重点强调安全性和常见错误。
  • 独立可执行文件(stand-alone executables),作为将Python应用打包并分发的替代方法。

Python打包一开始可能有些难以理解。其主要原因是不了解创建Python包的正确工具。不管怎样,一旦创建了第一个包,你就会发现它并不像看起来那么难。此外,熟悉正确且最先进的打包工具也很有帮助。

你即使对将代码开源分发不感兴趣,但也应该知道如何创建包。知道如何创建自己的包,可以让你深入了解打包生态系统,并且有助于你使用PyPI上可用的第三方代码。

此外,将你的闭源项目或其组件变成源代码发行包,有助于你在不同的环境中部署代码。下一章将会更详细地描述在代码部署过程中使用Python打包生态系统的优点。本章我们将重点介绍创建这些发行版的正确工具和技术。

Python打包曾经在很长一段时间内处于混乱不堪的状态,人们花了很多年才使得这一主题重新变得有组织。一切都从1998年引入的distutils包开始,随后在2003年setuptools ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Hadoop实际解决方案手册

Hadoop实际解决方案手册

Posts & Telecom Press, JONATHAN OWENS, Lentz Jon, Femiano Brian
TensorFlow机器学习

TensorFlow机器学习

Posts & Telecom Press, Quan Hua, Shams Ul Azeem, Saif Ahmed
Python和NLTK实现自然语言处理

Python和NLTK实现自然语言处理

Posts & Telecom Press, Nitin Hardeniya
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9781835887745