Beginning Python - From Novice to Professional

Beginning Python - From Novice to Professional Beginning Python - From Novice to Professional

16.01.2014 Views

CHAPTER 1 ■ INSTANT HACKING: THE BASICS 5 where packagename.src.rpm is the real file name of the package you’re rebuilding. After you have done this, you should have a brand-new set of RPM files that you can install as described previously. ■Note To use the RPM installation, you must be logged in as root (the administrator account). If you don’t have root access, you should compile Python yourself, as described in the section “Compiling from Sources,” later in this chapter. Other Installation Mechanisms for Linux There are several other package systems and installation mechanisms for Linux than rpm. If you’re running a Linux system with some form of package manager, chances are you can get Python through it. ■Note You will probably have to have administrator privileges (a root account) in order to install Python using a package manager in Linux. For example, if you’re running Debian Linux, you should be able to install Python with the following command: $ apt-get install python2.4 If you’re running Gentoo Linux, you should be able to use Portage, like this: $ emerge python In both cases, $ is, of course, the bash prompt. Replace 2.4 with the most recent version number. Compiling from Sources If you don’t have a package manager, or would rather not use it, you can compile Python yourself. This may be the method of choice if you are on a UNIX box but you don’t have root access (installation privileges). This method is very flexible, and enables you to install Python wherever you want, including in your own home directory. To compile and install Python, follow these steps: 1. Go to the download page (refer to steps 1 and 2 in the instructions for installing Python on a Windows system). 2. Follow the instructions for downloading the sources. 3. Download the file with the extension .tgz. Store it in a temporary location. Assuming that you want to install Python in your home directory, you may want to put it in a directory such as ~/python. Enter this directory (e.g., using cd ~/python).

6 CHAPTER 1 ■ INSTANT HACKING: THE BASICS 4. Unpack the archive with the command tar -xzvf Python-2.4.tgz (where 2.4 is the version number of the downloaded source code). If your version of tar doesn’t support the z option, you may want to uncompress the archive with gunzip first, and then use tar -xvf afterward. If there is something wrong with the archive, try downloading it again. Sometimes errors occur during download. 5. Enter the unpacked directory: $ cd Python-2.4 Now you should be able to execute the following commands: ./configure --prefix=$(pwd) make make install You should end up with an executable file called python in the current directory. (If this doesn’t work, please consult the README file included in the distribution.) Put the current directory in your PATH environment variable, and you’re ready to rock. To find out about the other configuration directives, execute ./configure --help Macintosh If you’re using a Macintosh, follow these steps: 1. Go to the standard download page (steps 1 and 2 from the Windows instructions earlier in this chapter). 2. Follow the link for the Macintosh OS X installer. There should also be a link to the MacPython download page, which has more information. The MacPython page also has versions of Python for older versions of the Macintosh OS. ■Note As of Python version 2.4, the OS X installer is still at version 2.3. Other Distributions You now have the standard Python distribution installed. Unless you have a particular interest in alternative solutions, that should be quite all right. If you are curious (and, perhaps, feeling a bit courageous), read on . . . There are other Python distributions, with the most well-known one being ActivePython. A slightly less well-known but quite interesting distribution is Stackless Python. These distributions are based on the standard implementation of Python, written in the C programming

CHAPTER 1 ■ INSTANT HACKING: THE BASICS 5<br />

where packagename.src.rpm is the real file name of the package you’re rebuilding. After you<br />

have done this, you should have a brand-new set of RPM files that you can install as described<br />

previously.<br />

■Note To use the RPM installation, you must be logged in as root (the administra<strong>to</strong>r account). If you don’t<br />

have root access, you should compile <strong>Python</strong> yourself, as described in the section “Compiling from Sources,”<br />

later in this chapter.<br />

Other Installation Mechanisms for Linux<br />

There are several other package systems and installation mechanisms for Linux than rpm. If<br />

you’re running a Linux system with some form of package manager, chances are you can get<br />

<strong>Python</strong> through it.<br />

■Note You will probably have <strong>to</strong> have administra<strong>to</strong>r privileges (a root account) in order <strong>to</strong> install <strong>Python</strong><br />

using a package manager in Linux.<br />

For example, if you’re running Debian Linux, you should be able <strong>to</strong> install <strong>Python</strong> with the<br />

following command:<br />

$ apt-get install python2.4<br />

If you’re running Gen<strong>to</strong>o Linux, you should be able <strong>to</strong> use Portage, like this:<br />

$ emerge python<br />

In both cases, $ is, of course, the bash prompt. Replace 2.4 with the most recent version<br />

number.<br />

Compiling from Sources<br />

If you don’t have a package manager, or would rather not use it, you can compile <strong>Python</strong> yourself.<br />

This may be the method of choice if you are on a UNIX box but you don’t have root access<br />

(installation privileges). This method is very flexible, and enables you <strong>to</strong> install <strong>Python</strong> wherever<br />

you want, including in your own home direc<strong>to</strong>ry. To compile and install <strong>Python</strong>, follow these steps:<br />

1. Go <strong>to</strong> the download page (refer <strong>to</strong> steps 1 and 2 in the instructions for installing <strong>Python</strong><br />

on a Windows system).<br />

2. Follow the instructions for downloading the sources.<br />

3. Download the file with the extension .tgz. S<strong>to</strong>re it in a temporary location. Assuming<br />

that you want <strong>to</strong> install <strong>Python</strong> in your home direc<strong>to</strong>ry, you may want <strong>to</strong> put it in a<br />

direc<strong>to</strong>ry such as ~/python. Enter this direc<strong>to</strong>ry (e.g., using cd ~/python).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!