Skip to content

Triangle Python Users Group: TriPython (formerly TriZPUG)

Sections
Personal tools
You are here: Home » Boot Camps » Toronto PyCamp 2011 » Installing Python for PyCamp

Installing Python for PyCamp

Document Actions
Python 2.6.6, the most widely used release of Python, will be used for Toronto PyCamp 2011. Read through the instructions for your operating system first before attempting the install. Then follow the instructions for class.

Contents

OSX
Windows
Linux

Installing Python on OSX 10.3 through 10.6

If you have not already installed the Xcode disc which came with your OSX, you should do so before performing any of the rest of this procedure.

Pick your OSX version:
Snow Leopard (OSX 10.6)
Leopard (OSX 10.5) or less

Installing Python on Snow Leopard (OSX 10.6)

  1. You are luckiest of all. Python 2.6.1 comes with Snow Leopard. And that's good enough for class. You are done.

Installing Python on OSX 10.5 or less (but at least 10.3)

  1. Download the Python 2.6.6 Mac OS X Installer Disk Image.
  2. Click on the downloaded DMG file to mount the disc image and open the Finder on the image.
  3. You'll notice a handy ReadMe.txt file on the disc image. You might want to click on it to read it in your favorite text editor. Or drag it to your favorite browser to view it there. License.txt is also interesting reading for some of the early history of Python.
  4. Click on the MPKG file on the disc image to start the installer.
  5. Click Continue on the installer to move past the Introduction dialog.
  6. ReadMe.txt appears again in case you didn't read it the before. Click Continue again when you are ready.
  7. License.txt appears again in case you didn't read it the before. Click Continue again when you are ready.
  8. At this point, unless you click on Agree indicating you agree to abide by Python Software Foundation License Version 2, you won't be getting very far in class. But it is a very generous license after all.
  9. Select the volume from which you boot OSX. If you install to something other than the boot volume, the install will appear to work. But it won't work properly enough for class. The installation only consumes 78 megabytes. Click Continue again after selecting your boot volume.
  10. Click Install. Unless you have very good reasons not to, you should not deselect any of the options under Customize. They are all very good and useful options. If you select Change Install Location, you will simply be taken back to the previous dialog where you selected the volume to which to install Python.
  11. Enter your login password and click OK when asked. This is to give OSX permission to install Python 2.6.6
  12. In less than one minute on a slow Macbook, the "Install Succeeded" dialog will appear. Click Close.
  13. Close the Finder window opened on the disk image.
  14. Ctrl-click on the Python 2.6.6 volume on your desktop.
  15. Click on "Eject Python 2.6.6.
  16. You now may delete the disk image file you downloaded if you wish. Or you may keep it. Your choice.
  17. Open Finder and look for the Python 2.6 folder in Applications.
  18. Click on IDLE.app in the Python 2.6 folder.
  19. You will see a Python prompt appear showing you that Python 2.6.6 is at your command.
  20. At the >>> prompt, type help() and press Enter.
  21. You are now at the Python Help prompt. A ridiculous amount of possibly helpful information is available here. "Possibly" depends on how much of a computer scientist you already are. Lucky for you, you're going to PyCamp!
  22. Ctrl-D exits the Python Help environment.
  23. Ctrl-D again exits Python.
  24. Feel awesome now. Because you are. You have just accomplished the most difficult task you will have to perform at PyCamp.
  25. Don't worry. Your system Python is still available at /System/Library/Frameworks/Python.framework/Versions/Current/bin/python.
  26. Don't worry. Any Pythons you had already installed yourself are still available at /Library/Frameworks/Python.framework/Versions.
  27. Your new Python 2.6.6 executable is installed at /Library/Frameworks/Python.framework/Versions/Current/bin/python.
  28. /Library/Frameworks/Python.framework/Versions/Current is a symbolic link to your default Python directory. You can see that the symbolic link points to /Library/Frameworks/Python.framework/Versions/2.6 by entering ls -l /Library/Frameworks/Python.framework/Versions/Current at a terminal prompt.
  29. You may invoke your new Python by entering python (all lower case) at a terminal prompt.
  30. You may prove this to yourself by entering which python (all lower case) at a terminal prompt.
  31. You know what a terminal prompt is don't you? Good. Because you will need to know how to find yours for class.
  32. iTerm is the most excellent free and open source terminal available for OSX. Much more so than the terminal built into OSX. Your PyCamp instructor wouldn't think of using another terminal besides iTerm. Two words: tabbed terminals.

Installing Python on Windows 2000 through Windows 7

  1. Log into Windows as a user with administrative privileges on the laptop (i.e., you are able to install programs). You will need to use this user in class as well. Don't come to class without access to a user with administrative privileges. If you own your own laptop, don't worry, your userid already has administrative privileges. If you are bringing a laptop from work, and only someone else has the authority to install new programs on that laptop, you will need to speak with that person and talk some sense into them.
  2. Download the Python 2.6.6 Windows installer.
  3. Double click on the installer to run it.
  4. Tell Windows, yes, I really want to run the installer, for however many times it asks. Do what you have to do.
  5. Leave "Install for all users" checked.
  6. Click Next to get past the installer Welcome dialog.
  7. When asked on the "Selection Destination Location" dialog, leave the install location as C:\Python26 unless you have a really good reason to do otherwise (for instance, you have ESRI ArcGIS already installed and you already let it install Python at C:\Python26).
  8. Click Next to go to the "Customize Python 2.6.6" dialog.
  9. Do not click on Advanced. Do not change the installation options. Click Next to install Python 2.6.6. The installation will only consume 78 megabytes of disk.
  10. In less than one minute on a slow netbook, you will see the "Completing the Python 2.6.6 installer dialog. Click Finish.
  11. You now may delete the installer file you downloaded if you wish. Or you may keep it. Your choice.
  12. Navigate to Start -> Programs -> Python 2.6. Click on IDLE (Python GUI). If you are running Windows Firewall, you may see an error message stating IDLE subprocesses could not communicate, as well as a dialog requesting you to allow Windows Firewall to allow IDLE subprocesses to communicate. If so, tell Windows Firewall to allow IDLE to communicate with itself and then restart IDLE.
  13. You will see a Python prompt appear showing you that Python 2.6.6 is at your command.
  14. At the >>> prompt, type help() and press Enter.
  15. You are now at the Python Help prompt. A ridiculous amount of possibly helpful information is available here. "Possibly" depends on how much of a computer scientist you already are. Lucky for you, you're going to PyCamp!
  16. Ctrl-D exits the Python Help environment.
  17. Ctrl-D again exits Python.
  18. Feel awesome now. Because you are. You have just accomplished the most difficult task you will have to perform at PyCamp.
  19. Your new Python 2.6.6 is installed at C:\Python26\python.exe.
  20. You may invoke your new Python by entering C:\Python26\python.exe at a command prompt. Ctrl-Z followed by the Enter key will exit Python and return you back to the command prompt.
  21. You know what a command prompt is don't you? Good. Because you will need to know how to find yours for class.
  22. Whoa, you aren't done yet. You will need the Python Extensions for Windows (aka pywin32) for class.
  23. Reboot your laptop to make sure Windows remembers Python 2.6.6 in its registry. This may seem silly but it really is an important an necessary step before proceeding.
  24. Download the pywin32 installer.
  25. Double click on the pywin32 installer to run it.
  26. Click OK when asked if you really want to run the pywin32 installer. (Vista may word this differently and may do so multiple times.)
  27. Click Run when notified that the publisher is unknown because he is an open source developer who has not paid Microsoft a ransom to identify his code to you.
  28. Click Next to get beyond the installer Welcome dialog.
  29. The installation location dialog should indicate "Python Version 2.6 (found in registry)." If so, then the Python and pywin32 installation directories will be correct already (C:\Python26\ and C:\Python26\Lib\site-packages\ respectively). Click Next.
  30. Click Next again to get more practice at clicking Next.
  31. In less than a minute, you will see the "Postinstall script finished" dialog. Click Finish.
  32. If you were paying attention to the Postinstall dialog, you may have noticed registry entries were made by the pywin32 installer. You know what that means. Time to reboot!
  33. If you know how to set environment variables, you may set your PATH system environment variable so that C:\Python26; and C:\Python26\Scripts are searched for python.exe and the various other programs the pywin32 installer created for you. Then you may simply enter python (all lower case) at your command prompt to start Python after yet another reboot.

Installing Python on Linux

Summary: All Linux distributions use Python for both installation of Linux itself and for installation and management of additional software packages from your Linux distribution's repository. The question is, which version of Python does your Linux distribution use for its central "system" Python? Either your Linux distribution already uses Python 2.6 as its system Python, or you will need to compile Python 2.6 from its freely available open source code in order to run Python 2.6 alongside the version of Python your system uses for managing itself.

Using a Built-in Python 2.6

  1. Python 2.6 is already installed as the system Python on most contemporary Linux systems. You can check to see if Python 2.6 is your system Python by entering python (all lower case) at a terminal prompt. If you see any version of Python 2.6 respond, that will suffice. Minor revisions of Python 2.6 such as Python 2.6.4 will work just fine for class. Exit Python by typing Ctrl-D.
  2. If Python 2.6 is not the system Python on your Linux, skip to Installing Python from Your Linux Distribution's Repository. Otherwise, use your Linux repository package manager (yum, Synaptic, etc.) to install the IDLE Python Integrated Development Environment package from your Linux distribution's repository. After installing IDLE, you may invoke IDLE at a command prompt by entering idle. You may exit IDLE through the File->Exit menu selection.
  3. Feel awesome now. Because you are. You have just accomplished the most difficult task you will have to perform at PyCamp.

Installing Python from Your Linux Distribution's Repository

  1. If you find that Python 2.6 is not the system Python on your Linux, you should first use your Linux repository package manager (yum, Synaptic, etc.) to look for Python 2.6 in your Linux repository and install Python 2.6 from there. If there is any way you can use the Python supported by your Linux distribution, that would be preferable for class. Later, when you become more expert in Python, you may find that you prefer compiling your own Python to using the Python from your distribution's repository. If Python 2.6 was not your system Python and you had to install it from your Linux repository, then you will likely need to invoke Python 2.6 by entering python2.6 instead of python. Your system Python is still installed and is invoked by entering python.
  2. If Python 2.6 is not available from your Linux distribution's repository, skip to Installing Python by Upgrading Your Linux Distribution. Otherwise, after installing Python 2.6 from your Linux distribution's repository, use your Linux repository package manager to install the IDLE Python Integrated Development Environment package from your Linux distribution's repository also. After installing IDLE, you may invoke IDLE at a command prompt by entering idle. You may exit IDLE through the File->Exit menu selection.
  3. Oops, the IDLE installed by your Linux repository package manager likely runs on your system Python instead of the Python 2.6 you just installed. There likely is no idle2.6 package in your Linux distribution's repository like there may be a python2.6 package if Python 2.6 is not your system Python. This will also be true of other add-on Python features from your Linux repository needed later during PyCamp. You need to proceed to Installing Python by Upgrading Your Linux Distribution afterall.

Installing Python by Upgrading Your Linux Distribution

If you find that Python 2.6 is not the system Python on your Linux, whether or not Python 2.6 is available from your Linux distribution's repository, then you should consider upgrading your Linux to a more contemporary distribution (such as Ubuntu 10.04, Fedora 13, or Debian 5). Then go back to the ease of Using a Built-in Python 2.6. Otherwise, proceed to Installing Python 2.6.6 from Scratch.

Installing Python 2.6.6 from Scratch

If you find that Python 2.6 is not the system Python on your Linux, whether or not Python 2.6 is available from your Linux distribution's repository, and upgrading your Linux to a more contemporary distribution is not practical, then you will need to compile and install Python from scratch:

  1. Log into Linux as your normal user, not as root. Your userid must have sudo privileges to proceed. If your userid does not have sudo privileges, you must find the administrator of your laptop and convince them to grant your userid sudo privileges before coming to class.
  2. Make sure you have the equivalent of the following prerequisites installed from your Linux repository before proceeding:
    • gcc
    • g++
    • zlib-dev
    • libjpeg-dev
    • openssl-dev
    • libreadline-dev
    • libxml2-dev
    • libsqlite3-dev
    • libbz2-dev
    • tk-dev
    • libgdbm-dev
  3. These prerequisites may go by different names on different Linux distributions. Installing any one of the above prerequisites may result in the installation of several dependencies for each prerequisite.
  4. Open a terminal prompt. Switch to your home directory: cd ~.
  5. Download the Python 2.6.6 compressed source tarball to your home directory: wget http://python.org/ftp/python/2.6.6/Python-2.6.6.tgz.
  6. Untar the file: tar -xzvf Python-2.6.6.tgz.
  7. Jump down into the untarred directory: cd Python-2.6.6.
  8. Configure your Python compilation steps: .\configure --prefix=/opt/python26 | tee configure.stdout.
  9. Compile Python: make | tee make.stdout. Go get some coffee. This is going to take awhile.
  10. If you just happen to run make test, which is completely optional, you will probably see a few messages which look like errors. This is actually very normal. A couple of the tests are broken. Many of them only apply to certain platforms (Mac, Sun, etc.). Some of them apply to features which are deprecated (i.e., scheduled for removal in Python 3.x, and therefore not maintained). And some of them require you to know how to turn on hardware resources for the tests to run. Running just the default test suite takes several minutes. Running the full test suite takes hours. You don't need to run the make test step. If your Python works for class, that's what you need. You should see it work in the next couple of steps of this installation procedure.

  11. Install your newly compiled Python 2.6: sudo make install | tee install.stdout. You will need to enter your password when sudo asks. This only takes a couple of minutes.
  12. See that your new Python works: /opt/python26/bin/python.
  13. You will see a Python prompt appear showing you that Python 2.6.6 is at your command.
  14. At the >>> prompt, type help() and press Enter.
  15. You are now at the Python Help prompt. A ridiculous amount of possibly helpful information is available here. "Possibly" depends on how much of a computer scientist you already are. Lucky for you, you're going to PyCamp!
  16. Ctrl-D exits the Python Help environment.
  17. Ctrl-D again exits Python.
  18. Feel awesome now. Because you are. You have just accomplished the most difficult task you will have to perform at PyCamp.
  19. If you installed the tk-dev prerequisite as asked, you may also invoke the IDLE Python Shell: /opt/python26/bin/idle. You may exit IDLE through the File->Exit menu selection.
  20. You may put /opt/python26/bin in your $PATH environment variable by creating (with sudo) a new file in /etc/profile.d called python26.sh. Give the file the following contents:
    export PATH=$PATH:/opt/python26/bin
    
    and make it immediately effective with source /etc/profile. python26.sh will run every time you reboot your Linux from now on. You should now take care to invoke Python 2.6 with python2.6. Your system Python is still invoked with python. Check your Linux repository package manager to see if IDLE is installed for the system Python. If it is, then remove it with the package manager. You won't need IDLE for your system Python. But you will need it for your Python 2.6 installation in class. If IDLE was not already installed for your system Python, or you have removed it from your system Python, then invoking idle at a terminal prompt will now start the IDLE associated with your custom-compiled Python.
  21. If the installation of Python or IDLE failed, then likely your Linux distribution simply cannot support Python 2.6 without some seriously individualized wizardry beyond the scope of PyCamp. You must more seriously reconsider Installing Python by Upgrading Your Linux Distribution if you expect to get much out of PyCamp.
  22. If worse comes to worse, and your Linux system Python is version 2.5, you may use that to follow along with 99% of the class material.
  23. If worst comes to worse, and your Linux system Python is version 2.4, you may use that to follow along with 95% of the class material.