预计阅读本页时间:-
Installation Steps
Once you’ve downloaded Python, you need to install it. Installation steps are very platform-specific, but here are a few pointers for the major Python platforms:
Windows
广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元
On Windows, Python comes as a self-installer MSI program file—simply double-click on its file icon, and answer Yes or Next at every prompt to perform a default install. The default install includes Python’s documentation set and support for tkinter (Tkinter in Python 2.6) GUIs, shelve databases, and the IDLE development GUI. Python 3.0 and 2.6 are normally installed in the directories C:\Python30 and C:\Python26, though this can be changed at install time.
For convenience, after the install Python shows up in the Start button’s All Programs menu. Python’s menu there has five entries that give quick access to common tasks: starting the IDLE user interface, reading module documentation, starting an interactive session, reading Python’s standard manuals in a web browser, and uninstalling. Most of these options involve concepts explored in detail elsewhere in this text.
When installed on Windows, Python also by default automatically registers itself to be the program that opens Python files when their icons are clicked (a program launch technique described in Chapter 3). It is also possible to build Python from its source code on Windows, but this is not commonly done.
One note for Windows Vista users: security features of the some versions of Vista change some of the rules for using MSI installer files. Although this may be a nonissue by the time you read these words, see the sidebar The Python MSI Installer on Windows Vista in this appendix for assistance if the current Python installer does not work, or does not place Python in the correct place on your machine.
Linux
On Linux, Python is available as one or more RPM files, which you unpack in the usual way (consult the RPM manpage for details). Depending on which RPMs you download, there may be one for Python itself, and another that adds support for tkinter GUIs and the IDLE environment. Because Linux is a Unix-like system, the next paragraph applies as well.
Unix
On Unix systems, Python is usually compiled from its full C source code distribution. This usually only requires you to unpack the file and run simple config and make commands; Python configures its own build procedure automatically, according to the system on which it is being compiled. However, be sure to see the package’s README file for more details on this process. Because Python is open source, its source code may be used and distributed free of charge.
On other platforms the installation details can differ widely, but they generally follow the platform’s normal conventions. Installing the “Pippy” port of Python for PalmOS, for example, requires a hotsync operation with your PDA, and Python for the Sharp Zaurus Linux-based PDA comes as one or more .ipk files, which you simply run to install it. Because additional install procedures for both executable and source forms are well documented, though, we’ll skip further details here.
The Python MSI Installer on Windows Vista
As I write this, the Python self-installer for Windows is an .msi installation file. This format works fine on Windows XP (simply double-click on the file, and it runs), but it can have issues on some versions of Windows Vista. In particular, running the MSI installer by clicking on it may cause Python to be installed at the root of the C: drive, instead of in the correct C:\PythonXX directory. Python still works in the root directory, but this is not the correct place to install it.
This is a Vista security-related issue; in short, MSI files are not true executables, so they do not correctly inherit administrator permissions, even if run by the administrator user. Instead, MSI files are run via the Windows Registry—their filenames are associated with the MSI installer program.
This problem seems to be either Python- or Vista-version specific. On a recent laptop, for example, Python 2.6 and 3.0 installed without issue. To install Python 2.5.2 on my Vista-based OQO handheld, though, I had to use a command-line approach to force the required administrator permissions.
If Python doesn’t install in the right place for you, here’s the workaround: go to your Start button, select the All Programs entry, choose Accessories, right-click on the Command Prompt entry there, choose “Run as administrator,” and select Continue in the access control dialog. Now, within the Command Prompt window, issue a cd command to change to the directory where your Python MSI installer file resides (e.g., cd C:\user\downloads), and then run the MSI installer manually by typing a command line of the form msiexec /i python-2.5.1.msi. Finally, follow the usual GUI interactions to complete the install.
Naturally, this behavior may change over time. This procedure may not be required in every version of Vista, and additional workarounds may be possible (such as disabling Vista security, if you dare). It’s also possible that the Python self-installer may eventually be provided in a different format that obviates this problem—as a true executable, for instance. Be sure to try your installer by simply clicking its icon to see if it works properly before attempting any workarounds.