Python Pygame For Mac



The official home of the Python Programming Language. While Javascript is not essential for this website, your interaction with the content will be limited. Installing Pygame for Python 3 on Mac and Linux 11 4. Hen the Pygame installation completes, open a file window W and go to Applications4 Programming4IDLE (using Python-3.4) to open the IDLE Python shell. Test your installation of Pygame for Python 3 on Linux by typing import pygame and pressing enter at the prompt, as shown in Figure 13.

This page does not represent the most current semester of this course; it is present merely as an archive.

Lab this week is optional in that we will not be taking roll. However, this is an opportunity to come to ensure that you have Python, PyCharm, and PyGame installed and working properly on your laptops. If you do not come to lab, we will assume you have taken care of this yourself and you are ready to go when we start coding in lecture next week. So, if you have any doubts, come on down to lab, meet some of the TAs, and make sure you’re laptop is setup and ready to go!

1.1 on Windows

  1. Install Python 3.6.4:

    1. Download the executable x86-64 installer from python.org.

    2. Run the installer.

    3. Choose the “Custom Installation” option.

    4. If asked, check “Add Python to environment variables” and “Install for all users”; leave all other options at their default values.

  2. Install PyCharm Community Edition 2017.3.2:

    1. Download the executable installer from jetbrains.com.

    2. Run the installer.

    3. If asked, check “Create associations” - “.py”; leave all other options at their default values.

  3. Set up PyCharm and PyGame; see the cross-platform information below.

1.2 on Mac

  1. Install Python 3.6.4:

    1. Download the installer from python.org.

    2. Run the installer.

    3. Choose the “Custom Installation” option.

    4. If asked, check “Add Python to environment variables” and “Install for all users”; leave all other options at their default values.

  2. Install PyCharm Community Edition 2017.3.2:

    1. Download the dmg disk image from jetbrains.com.

    2. Drag the icon to the Applications folder.

  3. Install prerequisites for PyGame

    1. Download and install XQuartz - https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.11.dmg.

    2. Open a Terminal window (/ApplicationsUtilitiesTerminal). In the terminal window, paste the following commands in one at a time and run them individually:

      1. xcode-select --install
      2. ruby -e '$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)'
      3. alias brew=/usr/local/bin/brew
      4. brew install sdl sdl_image sdl_ttf smpeg portmidi libogg libvorbis
      5. brew install sdl_mixer --with-libvorbis
    3. In the Finder, open /ApplicationsPython 3.6 and double-click on the icon for Install Certificates.command

  4. Set up PyCharm and PyGame; see the cross-platform information below.

1.3 On Other Systems

If you are using a system other than Windows or Mac (Linux, FreeBSD, Haiku, etc.), first off, good for you! In general, installing Python, PyGame, and PyCharm is pretty straightforward on these systems (download the Linux version of PyCharm even if you are using a BSD or the like), but if you have trouble post what system you are using on Piazza and we’ll help get you set up.

There’s a fair bit of set-up, but you should only have to do this once.

  1. Run PyCharm

  2. Accept the default options in the various screens that pop up asking you to set up various aspects of PyCharm. These should only appear the first time you run PyCharm.

  3. When you reach the welcome screen,

    set up PyGame and how Pycharm interacts with Python doing the following:

    1. In the “configuration” menu (gear icon), select “Settings”.

    2. Go to the “Project Interpreter” option on the left of the screen.

    3. If the “Project Interpreter” drop-down on the top of the screen has a “Python 3” of some kind, select it and skip the indented steps below; otherwise

      1. Click the gear icon beside the drop-down (top-right corner of the window) and select “Add Local…” from the menu
      2. In the pop-up window, on the left chose “System Interpreter”
      3. In the drop-down, pick python3.6 if it is present; if not, click the “…” button and find where you installed Python.

      4. Click OK

    4. Click the green + either to the top right or bottom left of the list of packages

    5. In the pop-up window, type pygame in the search bar, select “Pygame” in the left-hand list, and click “Install Package”

    6. Wait until an “installation successful” message appears

    7. Click “Apply” and “OK” in each window until back in the welcome screen

  4. Click “Create New Project”

  5. In the new project window

    1. Set the Location to some place you can find in your OS’s file browser; suggested:

      • Windows: C:Usersyour-user-name-on-your-computerDesktopcs1110
      • OS X: /Users/your-user-name-on-your-computer/Desktop/cs1110
    2. Expand the “Project Interpreter” with the little triangle and pick the “Existing Interpreter” option, with Python 3.6 as the interpreter.

    3. Click the Create button

  6. Create a new Python file by right-clicking (control-click if you only have one button) on the cs1110 folder in the Project pane on the left side of the window, then pick New → Python File

  7. Type setup_test.py in the new file pop-up

  8. In the editor window, type or paste the following:

  9. Right-click in white space in the editor window (not on any text) and select “Run setup_test” from the drop-down menu.

  10. If you see “Hello, world!” in the second line of the bottom of the window, everything is set up correctly!

    If you see something else, or if something went wrong along the way, ask a TA for help.

This has been a bugbear of mine for sometime now. I like using Python 3.x. I like teaching kids how to use Pygame. I use a Mac.Trying to get all three to play nicely with each other has been impossible for me up to now.

I've trawled through web pages and blog posts that recommend all manner of ways in which you can install Pygame on a Mac for Python 3, I've tried numerous solutions on StackOverflow, and I've even tried angrily shouting at my computer and threatening to throw it out of my classroom window. None of them worked.

Today I finally nailed it, and I have Pygame running. Here' what I did.

And that's it. If you have any problems yourself or a better way then please let me know in the comments.

note: the smpeg install is failing for me at the moment, so I'll look into this a little more. Pygame seems to be working without it though.

ForPython Pygame For MacPygame python 3.8

update

I had some brew doctor issues (around 20!), which might have been due to me trying to install Pygame from source earlier and therefore manually installing all the dependencies, which then conflicted with homebrew.

I deleted everything brew doctor suggested and overwrote all links as suggested. The brew install --HEAD smpeg suddenly worked (although that might have been because I was no longer behind a proxy). I then did a brew unlink jpeg and brew link --overwrite jpeg.

Python Pygame For Mac Os

Everything is working perfectly for now. (Crosses fingers, touches wood and searches for a black cat to cross his path.)