Книга: Teach Your Kids to Code: A Parent-Friendly Guide to Python Programming
Назад: A. Python Setup for Windows, Mac, and Linux
Дальше: C. Building Your Own Modules

Appendix B. Pygame Setup for Windows, Mac, and Linux

After installing Python (see ), you’ll want to install Pygame to run the animations and games in through . This appendix will get you up and running. If you’re installing Pygame on a computer at school or work, you may need help or permission from the IT department to perform the installation. If you run into issues, ask IT for help.

Pygame for Windows

For Windows, we’ll use Pygame 1.9.2 for Python 3.2 (see for help setting up Python 3.2.5).

  1. Go to and click the Downloads link on the left, as shown in .
    Click the Downloads link.
    Figure B-1. Click the Downloads link.
  2. Under the Windows section, find the link for pygame-1.9.2a0 .win32-py3.2.msi and click it to download the installer program, as shown in .
    Download the installer program for Windows.
    Figure B-2. Download the installer program for Windows.
  3. When the download finishes, open your Downloads folder to find the pygame-1.9.2a0.win32-py3.2 Windows Installer program file, as shown in . Double-click the file to begin installation. If a Security Warning window comes up, click Run. Windows is just letting you know the software is trying to install on your computer.
    Double-click the installer in your Downloads folder.
    Figure B-3. Double-click the installer in your Downloads folder.
  4. The installer might ask if you would like to install Pygame for all users or just for yourself. It’s usually best to choose Install for all users, but if that isn’t allowed at your school or office or you can’t get it to work, try Install just for me. Click Next >, as shown in .
    Install for all users.
    Figure B-4. Install for all users.
  5. The program should find your Python 3.2.5 installation from . Select Python 3.2 from registry. Click Next > to keep installing, as shown in . (If you’re installing at school or work and run into trouble, your IT staff may need to select the option for Python from another location.)
    Select Python 3.2 from registry.
    Figure B-5. Select Python 3.2 from registry.
  6. Once you’ve completed the installer, click Finish to exit, as shown in .
    Click Finish to exit.
    Figure B-6. Click Finish to exit.
  7. Go to StartProgramsPython 3.2IDLE (Python GUI), as shown in . (On Windows 8 and later, you can press the Windows/Start button, go to the Search tool, and type IDLE).
    Open IDLE from the Start menu.
    Figure B-7. Open IDLE from the Start menu.
  8. In the Python shell editor, type import pygame and press ENTER. The Python shell should respond with >>>, as shown in . If it does, then you know Pygame installed correctly and is ready to use.
    Import Pygame in the Python shell.
    Figure B-8. Import Pygame in the Python shell.

    Now you’re ready to run the programs from through . Happy coding!

Pygame for Mac

Installing Pygame on a Mac is more complicated than on a PC. You have three options:

  1. If you have access to a Windows PC, you may find it easier to install the Windows versions of Python and Pygame in order to run the programs from through . If you choose this option, follow the steps in . Then follow the steps in .
  2. You can install an older version of Python, like Python 2.7.9, along with Pygame 1.9.2 for OS X in order to run the Pygame programs in through . Installing Python 2.7.9 and Pygame 1.9.2 is easier than making Pygame work with Python 3.4.2. But there are differences between Python 2 and 3, so for through , I recommend sticking to Python 3.4.2 to make sure the examples work. Then, for through , you can use Python 2.7 and Pygame 1.9.2 to run the Pygame examples. If you choose this option, follow the steps under in the next section.
  3. To install Pygame for Python 3.4 on your Mac, see the instructions online at . If you’re doing this at school or work, you will almost certainly need IT support. Give your IT professional the online instructions to use as a guide.

Python 2.7 and Pygame 1.9.2

Newer Macs come with a version of Python 2.7 preinstalled by Apple as part of OS X. But the version of Python that Apple provides may not work with the Pygame installer. I recommend installing the latest version of Python 2.7 from before you try to install Pygame.

  1. To install Python 2.7 on your Mac, go back to and start following the steps under again. But this time, instead of downloading the 3.4.2 installer from the Mac downloads page at , download and run the 2.7 installer (2.7.9 as of this writing), as shown in .
    Install Python 2.7.
    Figure B-9. Install Python 2.7.
  2. The installation process for Python 2.7 should be similar to the installer for 3.4. Continue following the steps under in until you complete the installation.
  3. Check your Applications folder. There should now be a Python 2.7 folder in addition to your Python 3.4 folder, as shown in .
    You should have both Python 2.7 and Python 3.4.
    Figure B-10. You should have both Python 2.7 and Python 3.4.
  4. Go to , go to the Downloads page, and download the Pygame 1.9.2 installer for Python 2.7: pygame-1.9.2pre-py2.7-macosx10.7.mpkg.zip.
  5. Run the Pygame installer by holding down the CONTROL key, clicking the file, and selecting Open withInstaller from the pop-up menu that appears. The steps will be similar to those for installing Python: click Continue a few times, accept the license, and choose the installation drive. Click Close when the installer finishes.
  6. To test your Pygame installation, go to your Applications folder, select Python 2.7, and open IDLE. In IDLE for Python 2.7, type import pygame. IDLE should respond with >>>, as shown in .
    Import Pygame in the Python shell.
    Figure B-11. Import Pygame in the Python shell.
  7. You might get a pop-up notice like the one in saying that you need to install X11, a windowing system used by Pygame. Click Continue to go to the XQuartz website, . Download XQuartz-2.7.7.dmg, open the file, and run the installer package.
    Click Continue to install X11.
    Figure B-12. Click Continue to install X11.
  8. To run the Pygame programs in through , use Python 2.7 IDLE instead of Python 3.4 IDLE.

Note

On newer Macs with Retina displays, using Pygame with Python 2.7 looks a bit different than it does on other computers because Retina displays use a higher screen resolution. Your programs should work fine, but they will appear in a smaller area of the screen.


Pygame for Linux

Similar to installing Pygame on a Mac, you have two options for Pygame on Linux:

  1. You can install Pygame for Python 2, the version of Python that is likely to have come pre-installed as part of your version of Linux. For through , you’ll need to use Python 3, so follow the instructions in and use that version of IDLE for the apps in the first seven chapters. Then, for through , you can use Pygame for Python 2 to run the Pygame examples in those chapters. If you choose this option, follow the steps under in the next section.
  2. To install Pygame for Python 3.4 on Linux, see the instructions online at . If you’re doing this at school or work, you will likely need IT support. Give your IT professional the online instructions to use as a guide.

Pygame for Python 2

Most Linux operating systems come with Python installed already, usually Python 2. The game-based and graphical apps in through can run just fine on this older version of Python. The following steps will get Pygame up and running on your Linux system.

  1. In the Dash menu, go to System Tools and run the Synaptic Package Manager or similar application for your version of Linux. shows the package manager running on Lubuntu.
    Installing Pygame for Python 2 on Linux
    Figure B-13. Installing Pygame for Python 2 on Linux
  2. Search for python-pygame. Check the box next to python-pygame in the search results and click Apply to complete the installation.
  3. Run System ToolsTerminal (or XTerm or a similar application for your version of Linux). You can start Python 2 by entering python2 in the terminal window. Then test your Pygame installation by entering import pygame at the >>> prompt as shown in . Python should reply with >>> to let you know that Pygame was successfully imported.
    You can test your installation of Pygame for Python 2 from the Linux command line terminal.
    Figure B-14. You can test your installation of Pygame for Python 2 from the Linux command line terminal.
  4. You can use the Software Center (as shown in ) or the Synaptic Package Manager shown in to search for and install IDLE for Python 2. Use this version of IDLE when running the Pygame apps from through .
Назад: A. Python Setup for Windows, Mac, and Linux
Дальше: C. Building Your Own Modules

Francisco
Mexico
Elldrerse
Cialis Levitra Comment Viagra Mens Ed Medications Online Pharmacy Priligy Cialis 100mg
Kbcxsame
prescription drugs without doctor approval canadian pharmacy meds pharmacies shipping to usa
Kvaxsame
american cash advance broadview small payday loans bad credit direct lender los angeles times payday loans
JbnvJinge
cash store loans ontario what happens if i don't pay back a payday loan in ohio getting a payday loan without a bank account
FqbbAmurn
cash advance avon in merced payday loans cash loans in opelika al
Cnukitels
thesis writing assistance thesis in writing
Inpuripeni
stromectol pills
Inpuripeni
ivermectin cost uk
nqzywpex
fougera erythromycin ophthalmic ointment mechanism of action of erythromycin