mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 15:00:18 +00:00
282 lines
20 KiB
HTML
282 lines
20 KiB
HTML
<!DOCTYPE html>
|
|
<head>
|
|
<meta charset=utf-8>
|
|
<title>Installing Python - Dive into Python 3</title>
|
|
<!--[if IE]><script src=j/html5.js></script><![endif]-->
|
|
<link rel=stylesheet href=dip3.css>
|
|
<style>
|
|
body{counter-reset:h1 0}
|
|
.i{list-style:none;margin:0;padding:0}
|
|
#which{padding-top:1.75em}
|
|
h2,.i>li{clear:both}
|
|
.i li .ss{float:right;margin:0 0 1.75em 1.75em}
|
|
</style>
|
|
<link rel=stylesheet type=text/css media='only screen and (max-device-width: 480px)' href=mobile.css>
|
|
<link rel=stylesheet media=print href=print.css>
|
|
<meta name=viewport content='initial-scale=1.0'>
|
|
</head>
|
|
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
|
<p>You are here: <a href=index.html>Home</a> <span class=u>‣</span> <a href=table-of-contents.html#installing-python>Dive Into Python 3</a> <span class=u>‣</span>
|
|
<p id=level>Difficulty level: <span class=u title=novice>♦♢♢♢♢</span>
|
|
<h1>Installing Python</h1>
|
|
<blockquote class=q>
|
|
<p><span class=u>❝</span> <i lang=la>Tempora mutantur nos et mutamur in illis.</i> (Times change, and we change with them.) <span class=u>❞</span><br>— ancient Roman proverb
|
|
</blockquote>
|
|
<p id=toc>
|
|
<h2 id=divingin>Diving in</h2>
|
|
<p class=f>Welcome to Python 3. Let's dive in. In this chapter, you'll install the version of Python 3 that's right for you.
|
|
|
|
<h2 id=which>Which Python Is Right For You?</h2>
|
|
|
|
<p>The first thing you need to do with Python is install it. Or do you?
|
|
|
|
<p>If you're using an account on a hosted server, your <abbr>ISP</abbr> may have already installed Python 3. If you’re running Linux at home, you may already have Python 3, too. Most popular GNU/Linux distributions come with Python 2 in the default installation; a small but growing number of distributions also include Python 3. (As you’ll see in this chapter, you can have more than one version of Python installed on your computer.) Mac OS X includes a command-line version of Python 2, but as of this writing it does not include Python 3. Microsoft Windows does not come with any version of Python. But don’t despair! You can point-and-click your way through installing Python, regardless of what operating system you have.
|
|
|
|
<p>The easiest way to check for Python 3 on your Linux or Mac OS X system is to get to a command line. On Linux, look in your <b><code>Applications</code></b> menu for a program called <b><code>Terminal</code></b>. (It may be in a submenu like <b><code>Accessories</code></b> or <b><code>System</code></b>.) On Mac OS X, there is an application called <b><code>Terminal.app</code></b> in your <code>/Application/Utilities/</code> folder.
|
|
|
|
<p>Once you’re at a command line prompt, just type <kbd>python3</kbd> (all lowercase, no spaces) and see what happens. On my home Linux system, Python 3 is already installed, and this command gets me into the <i>Python <dfn>interactive shell</dfn></i>.
|
|
|
|
<pre class=screen>
|
|
<samp class=p>mark@atlantis:~$ </samp><kbd>python3</kbd>
|
|
<samp>Python 3.0.1+ (r301:69556, Apr 15 2009, 17:25:52)
|
|
[GCC 4.3.3] on linux2
|
|
Type "help", "copyright", "credits" or "license" for more information.
|
|
>>></samp></pre>
|
|
|
|
<p>(Type <kbd>exit()</kbd> and press <kbd>ENTER</kbd> to exit the Python interactive shell.)
|
|
|
|
<p>My <a href=http://cornerhost.com/>web hosting provider</a> also runs Linux and provides command-line access, but my server does not have Python 3 installed. (Boo!)
|
|
|
|
<pre class=screen>
|
|
<samp class=p>mark@manganese:~$ </samp><kbd>python3</kbd>
|
|
<samp>bash: python3: command not found</samp></pre>
|
|
|
|
<p>So back to the question that started this section, “Which Python is right for you?” The answer is whichever one runs on the computer you already have.
|
|
|
|
<p>[Read on for Windows instructions, or skip to <a href=#macosx>Installing on Mac OS X</a>, <a href=#ubuntu>Installing on Ubuntu Linux</a>, or <a href=#other>Installing on Other Platforms</a>.]
|
|
|
|
<p class=a>⁂
|
|
|
|
<h2 id=windows>Installing on Microsoft Windows</h2>
|
|
|
|
<p>Windows comes in two architectures these days: 32-bit and 64-bit. Of course, there are lots of different <i>versions</i> of Windows — XP, Vista, Windows 7 — but Python runs on all of them. The more important distinction is 32-bit v. 64-bit. If you have no idea what architecture you’re running, it’s probably 32-bit.
|
|
|
|
<p>Visit <a href=http://python.org/download/><code>python.org/download/</code></a> and download the appropriate Python 3 Windows installer for your architecture. Your choices will look something like this:
|
|
|
|
<ul>
|
|
<li><b>Python 3.1 Windows installer</b> (Windows binary — does not include source)
|
|
<li><b>Python 3.1 Windows AMD64 installer</b> (Windows AMD64 binary — does not include source)
|
|
</ul>
|
|
|
|
<p>I don’t want to include direct download links here, because minor updates of Python happen all the time and I don’t want to be responsible for you missing important updates. You should always install the most recent version of Python 3.x unless you have some esoteric reason not to.
|
|
|
|
<ol class=i>
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-install-0-security-warning.png width=409 height=309 alt='[Windows dialog: open file security warning]'>
|
|
<p>Once your download is complete, double-click the <code>.msi</code> file. Windows will pop up a security alert, since you’re about to be running executable code. The official Python installer is digitally signed by the <a href=http://www.python.org/psf/>Python Software Foundation</a>, the non-profit corporation that oversees Python development. Don’t accept imitations!
|
|
<p>Click the <code>Run</code> button to launch the Python 3 installer.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-install-1-all-users-or-just-me.png width=499 height=432 alt='[Python installer: select whether to install Python 3.1 for all users of this computer]'>
|
|
<p>The first question the installer will ask you is whether you want to install Python 3 for all users or just for you. The default choice is “install for all users,” which is the best choice unless you have a good reason to choose otherwise. (One possible reason why you would want to “install just for me” is that you are installing Python on your company’s computer and you don’t have administrative rights on your Windows account. But then, why are you installing Python without permission from your company’s Windows administrator? Don’t get me in trouble here!)
|
|
<p>Click the <code>Next</code> button to accept your choice of installation type.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-install-2-destination-directory.png width=499 height=432 alt='[Python installer: select destination directory]'>
|
|
<p>Next, the installer will prompt you to choose a destination directory. The default for all versions of Python 3.1.x is <code>C:\Python31\</code>, which should work well for most users unless you have a specific reason to change it. If you maintain a separate drive letter for installing applications, you can browse to it using the embedded crontrols, or simply type the pathname in the box below. You are not limited to installing Python on the <code>C:</code> drive; you can install it on any drive, in any folder.
|
|
<p>Click the <code>Next</code> button to accept your choice of destination directory.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-install-3-customize.png width=499 height=432 alt='[Python installer: customize Python 3.1]'>
|
|
<p>The next page looks complicated, but it’s not really. Like many installers, you have the option not to install every single component of Python 3. If disk space is especially tight, you can exclude certain components.
|
|
<ul>
|
|
<li><b>Register Extensions</b> allows you to double-click Python scripts (<code>.py</code> files) and run them. Recommended but not required. (This option doesn’t require any disk space, so there is little point in excluding it.)
|
|
<li><b>Tcl/Tk</b> is the graphics library used by the Python Shell, which you will use throughout this book. I strongly recommend keeping this option.
|
|
<li><b>Documentation</b> installs a help file that contains much of the information on <a href=http://docs.python.org/><code>docs.python.org</code></a>. Recommended if you are on dialup or have limited Internet access.
|
|
<li><b>Utility Scripts</b> includes the <code>2to3.py</code> script which you’ll learn about <a href=case-study-porting-chardet-to-python-3.html>later in this book</a>. Required if you want to learn about migrating existing Python 2 code to Python 3. If you have no existing Python 2 code, you can skip this option.
|
|
<li><b>Test Suite</b> is a collection of scripts used to test the Python interpreter itself. We will not use it in this book, nor have I ever used it in the course of programming in Python. Completely optional.
|
|
</ul>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-install-3a-disk-usage.png width=499 height=432 alt='[Python installer: disk space requirements]'>
|
|
<p>If you’re unsure how much disk space you have, click the <code>Disk Usage</code> button. The installer will list your drive letters, compute how much space is available on each drive, and calculate how much would be left after installation.
|
|
<p>Click the <code>OK</code> button to return to the “Customizing Python*#8221; page.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-install-3b-test-suite.png width=499 height=432 alt='[Python installer: removing Test Suite option will save 7908KB on your hard drive]'>
|
|
<p>If you decide to exclude an option, select the drop-down button before the option and select “Entire feature will be unavailable.” For example, excluding the test suite will save you a whopping 7908<abbr>KB</abbr> of disk space.
|
|
<p>Click the <code>Next</code> button to accept your choice of options.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-install-4-copying.png width=499 height=432 alt='[Python installer: progress meter]'>
|
|
<p>The installer will copy all the necessary files to your chosen destination directory. (This happens so quickly, I had to try it three times to even get a screenshot of it!)
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-install-5-finish.png width=499 height=432 alt='[Python installer: installation completed. Special Windows thanks to Mark Hammond, without whose years of freely shared Windows expertise, Python for Windows would still be Python for DOS.]'>
|
|
<p>Click the <code>Finish</code> button to exit the installer.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/win-interactive-shell.png width=677 height=715 alt='[Windows Python Shell, a graphical interactive shell for Python]'>
|
|
<p>In your <code>Start</code> menu, there should be a new item called <code>Python 3.1</code>. Within that, there is a program called <abbr>IDLE</abbr>. Select this item to run the interactive Python Shell.
|
|
|
|
</ol>
|
|
|
|
<p>[Skip to <a href=#idle>using the Python Shell</a>]
|
|
|
|
<p class=a>⁂
|
|
|
|
<h2 id=macosx>Installing on Mac OS X</h2>
|
|
|
|
<p>All modern Macintosh computers use the Intel chip (like most Windows PCs). Older Macs used PowerPC chips. You don’t need to understand the difference, because there’s just one Mac Python installer for all Macs.
|
|
|
|
<p>Visit <a href=http://python.org/download/><code>python.org/download/</code></a> and download the Mac installer. It will be called something like <b>Python 3.1 Mac Installer Disk Image</b>, although the version number may vary. Be sure to download version 3.x, not 2.x.
|
|
|
|
<ol class=i>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-0-dmg-contents.png width=752 height=438 alt='[contents of Python installer disk image]'>
|
|
<p>Your browser should automatically mount the disk image and open a Finder window to show you the contents. (If this doesn’t happen, you’ll need to find the disk image in your downloads folder and double-click to mount it. It will be named something like <code>python-3.1.dmg</code>.) The disk image contains a number of text files (<code>Build.txt</code>, <code>License.txt</code>, <code>ReadMe.txt</code>), and the actual installer package, <code>Python.mpkg</code>.
|
|
<p>Double-click the <code>Python.mpkg</code> installer package to launch the Mac Python installer.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-1-welcome.png width=622 height=442 alt='[Python installer: welcome screen]'>
|
|
<p>The first page of the installer gives a brief description of Python itself, then refers you to the <code>ReadMe.txt</code> file (which you didn’t read, did you?) for more details.
|
|
<p>Click the <code>Continue</code> button to move along.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-2-information.png width=622 height=442 alt='[Python installer: information about supported architectures, disk space, and acceptable destination folders]'>
|
|
<p>The next page actually contains some important information: Python requires Mac OS X 10.3 or later. If you are still running Mac OS X 10.2, you should really upgrade. Apple no longer provides security updates for your operating system, and your computer is probably at risk if you ever go online. Also, you can’t run Python 3.
|
|
<p>Click the <code>Continue</code> button to advance.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-3-license.png width=622 height=442 alt='[Python installer: software license agreement]'>
|
|
<p>Like all good installers, the Python installer displays the software license agreement. Python is open source, and its license is <a href=http://opensource.org/licenses/>approved by the Open Source Initiative</a>. Python has had a number of owners and sponsors throughout its history, each of which has left its mark on the software license. But the end result is this: Python is open source, and you may use it on any platform, for any purpose, without fee or obligation of reciprocity.
|
|
<p>Click the <code>Continue</code> button once again.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-4-license-dialog.png width=622 height=442 alt='[Python installer: dialog to accept license agreement]'>
|
|
<p>Due to quirks in the standard Apple installer framework, you must “agree” to the software license in order to complete the installation. Since Python is open source, you are really “agreeing” that the license is granting you additional rights, rather than taking them away.
|
|
<p>Click the <code>Agree</code> button to continue.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-5-standard-install.png width=622 height=442 alt='[Python installer: standard install screen]'>
|
|
<p>The next screen allows you to change your install location. You <strong>must</strong> install Python on your boot drive, but due to limitations of the installer, it does not enforce this. In truth, I have never had the need to change the install location.
|
|
<p>From this screen, you can also customize the installation to exclude certain features. If you want to do this, click the <code>Customize</code> button; otherwise click the <code>Install</code> button.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-6-custom-install.png width=622 height=442 alt='[Python installer: custom install screen]'>
|
|
<p>If you choose a Custom Install, the installer will present you with the following list of features:
|
|
<ul>
|
|
<li><b>Python Framework</b>. This is the guts of Python, and is both selected and disabled because it must be installed.
|
|
<li><b>GUI Applications</b> includes IDLE, the graphical Python Shell which you will use throughout this book. I strongly recommend keeping this option selected.
|
|
<li><b>UNIX command-line tools</b> includes the command-line <code>python3</code> application. I strongly recommend keeping this option, too.
|
|
<li><b>Python Documentation</b> contains much of the information on <a href=http://docs.python.org/><code>docs.python.org</code></a>. Recommended if you are on dialup or have limited Internet access.
|
|
<li><b>Shell profile updater</b> FIXME WTF is this?
|
|
<li><b>Fix system Python</b> FIXME WTF is this too?
|
|
</ul>
|
|
<p>Click the <code>Install</code> button to continue.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-7-admin-password.png width=622 height=457 alt='[Python installer: dialog to enter administrative password]'>
|
|
<p>Because it installs system-wide frameworks and binaries in <code>/usr/local/bin/</code>, the installer will ask you for an administrative password. There is no way to install Mac Python without administrator privileges. (FIXME really?)
|
|
<p>Click the <code>OK</code> button to begin the installation.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-8-progress.png width=622 height=442 alt='[Python installer: progress meter]'>
|
|
<p>The installer will display a progress meter while it installs the features you’ve selected.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-9-succeeded.png width=622 height=442 alt='[Python installer: install succeeded]'>
|
|
<p>Assuming all went well, the installer will give you a big green checkmark to tell you that the installation completed successfully.
|
|
<p>Click the <code>Close</code> button to exit the installer.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-install-10-application-folder.png width=488 height=482 alt='[contents of /Applications/Python 3.1/ folder]'>
|
|
<p>Assuming you didn’t change the install location, you can find the newly installed files in the <code>Python 3.1</code> folder within your <code>/Applications</code> folder. The most important piece is <abbr>IDLE</abbr>, the graphical Python Shell.
|
|
<p>Double-click <abbr>IDLE</abbr> to launch the Python Shell.
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-interactive-shell.png width=522 height=538 alt='[Mac Python Shell, a graphical interactive shell for Python]'>
|
|
<p>The Python Shell is where you will spend most of your time exploring Python. Examples throughout this book will assume that you can find your way into the Python Shell.
|
|
|
|
<!--
|
|
<li>
|
|
<p class='ss nm'><img src=i/mac-pythonlauncher.png width=432 height=536 alt='[Python Launcher preferences window]'>
|
|
-->
|
|
</ol>
|
|
|
|
<p>[Skip to <a href=#idle>using the Python Shell</a>]
|
|
|
|
<p class=a>⁂
|
|
|
|
<h2 id=ubuntu>Installing on Ubuntu Linux</h2>
|
|
|
|
<p>FIXME
|
|
|
|
<ol class=i>
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-0-add-remove-programs.png width=920 height=473 alt='[Add/Remove: Canonical-maintained applications]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-1-all-open-source-applications.png width=920 height=473 alt='[Add/Remove: all open source applications]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-2-search-python-3.png width=920 height=473 alt='[Add/Remove: search for Python 3]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-3-select-python-3.png width=920 height=473 alt='[Add/Remove: select Python 3.0 package]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-4-select-idle.png width=920 height=473 alt='[Add/Remove: select IDLE for Python 3.0 package]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-5-apply-changes.png width=635 height=364 alt='[Add/Remove: apply changes]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-6-download-progress.png width=287 height=211 alt='[Add/Remove: download progress meter]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-7-install-progress.png width=486 height=258 alt='[Add/Remove: installation progress meter]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-install-8-success.png width=591 height=296 alt='[Add/Remove: new applications have been installed]'>
|
|
|
|
<li>
|
|
<p class='ss nm'><img src=i/ubu-interactive-shell.png width=679 height=687 alt='[Linux Python Shell, a graphical interactive shell for Python]'>
|
|
|
|
</ol>
|
|
|
|
<p>[Skip to <a href=#idle>using the Python Shell</a>]
|
|
|
|
<p class=a>⁂
|
|
|
|
<h2 id=other>Installing on Other Platforms</h2>
|
|
|
|
<p>FIXME
|
|
|
|
<p class=a>⁂
|
|
|
|
<h2 id=idle>Using The Python Shell</h2>
|
|
|
|
<p>FIXME
|
|
|
|
<p class=a>⁂
|
|
|
|
<h2 id=editors>Python Editors and IDEs</h2>
|
|
|
|
<p>FIXME
|
|
<pre>
|
|
http://wiki.python.org/moin/PythonEditors
|
|
http://wiki.python.org/moin/IntegratedDevelopmentEnvironments
|
|
http://pydev.sourceforge.net/
|
|
http://www.activestate.com/komodo/
|
|
http://www.activestate.com/activepython/
|
|
</pre>
|
|
|
|
<p class=v><a href=whats-new.html rel=prev title='back to “What’s New In Dive Into Python 3”'><span class=u>☜</span></a> <a href=your-first-python-program.html rel=next title='onward to “Your First Python Program”'><span class=u>☞</span></a>
|
|
|
|
<p class=c>© 2001–9 <a href=about.html>Mark Pilgrim</a>
|
|
<script src=j/jquery.js></script>
|
|
<script src=j/prettify.js></script>
|
|
<script src=j/dip3.js></script>
|