Skip to Content
《学习 Python》第 5 版
book

《学习 Python》第 5 版

by Mark Lutz
May 2025
Intermediate to advanced
1648 pages
23h 5m
Chinese
O'Reilly Media, Inc.
Content preview from 《学习 Python》第 5 版

附录 A. 安装和配置

本附录提供了额外的安装和配置细节,作为初学者的参考资料。之所以将其放在这里,是因为并非所有读者都需要预先处理这些主题。 不过,由于它涵盖了环境变量和命令行参数等一些外围主题,这些材料可能至少值得大多数读者快速浏览一下。

安装 Python 解释器

因为运行 Python 脚本需要Python 解释器,所以使用 Python 的第一步通常是安装 Python。除非您的机器上已经有一个可用的 Python,否则您需要在计算机上获取、安装并配置一个最新版本的 Python。每台机器只需要做一次,如果运行的是冻结的二进制系统(在第 2 章中描述)或自安装系统,那么设置任务可能很琐碎或根本不需要。

Python 已经存在了吗?

在做任何其他事情之前,请检查您的计算机上是否已经安装了最新的 Python。如果您使用的是 Linux、Mac OS X 或某些 Unix 系统,那么您的计算机上很可能已经安装了 Python,尽管它可能比最前沿的版本晚一到两个版本。 下面是检查的方法:

  • Windows 7及更早版本中,请检查 "开始 "按钮的 "所有程序 "菜单(位于屏幕左下方)中是否有 Python 条目。在Windows 8 上,请在 "开始 "屏幕磁贴、搜索工具、"开始 "屏幕上的 "所有程序 "显示或桌面模式下的文件资源管理器中查找 Python(有关 Windows 8 的更多信息,请参阅即将推出的边栏)。

  • Mac OS X 上,打开终端窗口(应用程序→实用工具→终端),然后在提示符下键入 python在提示符下输入Python、IDLE 及其 tkinter GUI 工具包是该系统的标准组件。

  • LinuxUnix 上,在 shell 提示符(又称终端窗口)下键入 python看看会发生什么。或者,在常用的地方搜索 "python"--/usr/bin、/usr/local/bin 等。与 Mac 一样,Python 也是 Linux 系统的标准配置。

如果您找到了 Python,请确保它是最新版本。虽然任何最新版本的 Python 都能胜任本文的大部分内容,但本版特别关注 Python 3.3 和 2.7,因此您可能需要安装其中的一个版本来运行本书中的一些示例。

说到版本,根据前言,如果您正在重新学习 Python 并且不需要处理现有的 2.X 代码,我建议您从 Python 3.3 或更高版本开始;否则,您一般应该使用 Python 2.7。不过,一些流行的基于 Python 的系统仍在使用较旧的版本(2.6 甚至 2.5 仍很普遍),所以如果您正在使用现有的系统,请确保使用与您的需求相关的版本;下一节将介绍您可以获取各种 Python 版本的位置。

从哪里获取 Python

如果您的机器上没有 Python,您需要自己安装一个。好消息是,Python 是一个开源系统,可以在网络上免费获取,而且在大多数平台上都非常容易安装。

您可以随时从 Python 的官方网站http://www.python.org 获取最新、最好的标准 Python版本。在该页面上查找 "下载"(Downloads)链接,然后为您要运行的平台选择一个版本。您可以找到Windows的预制自安装文件(运行即可安装)、Mac OS X的安装磁盘映像(按照 Mac 惯例安装)、完整的源代码发行版(通常在 Linux、Unix 或 OS X 机器上编译以生成解释器)等。

虽然 Python 如今是Linux的标准配置,但您也可以在网上找到 Linux 的 RPM(用 rpm 解压)。Python ...

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

学习 Java,第 6 版

学习 Java,第 6 版

Marc Loy, Patrick Niemeyer, Daniel Leuck
《高性能 Python》第二版

《高性能 Python》第二版

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9798341656963