Skip to main content

Python 3.8 and Pygame 2.0

One of my goals for the year has been to learn Python. I got started on it earlier this year, but a move to a different state got me out of my routine of studying it every day, so its been a couple months since I last looked at it.

Now that I am all settled in here I decided to pick up where I left off, but change things up a bit.  I had been working my way through Christian Thompson's excellent series on creating a Space Invaders clone in Python and had successfully gotten a little spaceship moving around, and a couple enemies on screen that could be fired at, and register a hit.

However this tutorial uses Python Turtle and I decided that I wanted to learn with Pygame, since that is quite a bit more capable than Turtle and learning it would enable me to theoretically build games down the road. The chances of that happening are quite remote, as I am primarily interested in learning Python as a tool for data analysis to augment my FileMaker development skills, but I think it will make learning Python a lot more fun if I focus on simple game development first.

Turtle is also extremely slow, and I was seeing noticeable slowdown on my MacBook Pro with only two enemies moving on screen, plus my little triangle spaceship. Hopefully Pygame will not suffer from the same problem.

To assist me, I purchased Python Crash Course by Eric Matthes, second edition. It focuses solely on Python 3, so its far more future proof than a lot of other resources I had found, and I like the way it is organized and takes you from novice all the way up to game development in Pygame (Chapter 12-14) data analysis and visualization(Chapters 15-17) and web applications with Django (Chapters 18-20).

Since I already have a more or less solid understanding of loops, conditionals, lists (arrays), and variables, I decided to get set up and start working through the Space Invaders section (time will tell if this turns out to be unwarranted self-confidence or not).

Anyhow, the first step I needed to do was to install Pygame on my MacBook. So, following the book's instructions, I opened up the Terminal and attempted to run the following command:

$ python -m pip install --user pygame

This crashed and burned. I got a screen full of errors in the terminal every time I ran it, including a GCC error and a Pip error. I am not more than a basic terminal user, so I started Googling and trying to read through the Terminal log to see if anything made any sense. It did tell me that I should update Pip to version 20, but all attempts to do so failed. And the GCC error didn't make any sense as I know I have a version of GCC installed.

After extensive Googling (and trying multiple failed things that I don't really remember), I finally realized that the problem seemed to be that Mac OSX does not have Pip installed by default and I needed to install Homebrew.

Several attempts to install it failed, until I found the following command.

$ brew install python3 hg sdl sdl_image sdl_mixer sdl_ttf portmidi

That thought for a while and then Presto! I had Homebrew all installed and ready to go. Now to see if Pygame would install.

$ pip3 install hg+http://bitbucket.org/pygame/pygame

Nope. I got a massive screen full of red text and the relevant line seemed to be:

 36 warnings and 8 errors generated.
    error: command 'gcc' failed with exit status 1

This was very frustrating, especially since the only advice the book had regarding failed attempts to install Pygame was to say that if 

$ python -m pip install --user pygame

failed, I should run the command again without the "--user" flag. This did no good, either before or after installing Homebrew.

Further Googling turned up a Reddit thread that seemed to indicate that the problem is actually that the version of Pygame I was trying to install, did not work with versions of Python3 later than 3.7, and I am running 3.8.1. 

The suggested fix was using the easy_install command, instead of the pip command. So I entered:

$ easy_install pygame

And it failed miserably yet again. Except this time it gave an error that it didn't have write access to the directory it needed to write Pygame installation files to. Well, one of the few Unix commands I know is sudo, so I entered:

$ sudo easy_install pygame

It failed as well, although not with any error messages. Rather, it said it had installed it. However, when running the Python interpreter from the command line and telling it to import pygame, the Pygame module was not found. 

Well that was fun. I knew from my evening of googling that I should be able to use Pip now since I had Homebrew installed. But that had already failed multiple times. However I found a different variant of Pip to try:

$ python3 -m pip install pygame==2.0.0.dev6

Success! Pygame installed itself with no issues whatsoever. Running the import pygame command from inside the Python interpreter returned a Pygame version of 2.0.0.dev6. 

I am not knowledgeable enough to know exactly why I ran into the issues I did, but at least I muddled my way through to a solution. If anybody else is struggling to install Pygame on a newer Mac running Python 3.8, know that you probably need to install Homebrew first, and then run the above Pip command for Pygame 2.0 or later.

Comments

Popular posts from this blog

Soviet Mainframe Computers

Ural-1 Control Unit The world of Soviet tech is an interesting one, they frequently were forced to resort to workarounds as they attempted to compensate for their lagging technological development when compared to the West. This does not detract from their very real accomplishments in areas such as the space race, where they led the West for years before finally irrevocably falling behind after the untimely death of their leading designer, Sergei Korolev in 1966. I recently purchased an entire book on eBay called The Technological Level of Soviet Industry, (archived 1978 review  here , there is no direct link to buy it as even Amazon doesn't seem to have it). This isn't a full book, rather it is a collection of different author's papers all bound together. I purchased the book specifically to get Chapter 8, Computer technology  which is an extremely good resource on the state of Soviet computing in the late 70s. At the time of publication in 1977, personal computers...

Rise to Revolt Update

I have chosen to keep from releasing R2R on any other platform other than Kobo. Why? Because when it comes down to it, I learned so much from writing it, and feel that I developed enough as a writer from writing it, that I do not want to put it on the market in its current state. It's a good story, and I love the universe...but I am very aware of the flaws that are present in it. It still is something I am proud of because I finished it, and because I feel that the universe building in it is a strong point. I read somewhere that only about one in four people who say they intend to write a novel, actually follow through and finish something.  I have no idea how reliable a statistic that is, but anyway you look at it, it is an accomplishment to actually finish writing a book. Too many aspiring authors are always talking about the great thing that they are going to write, but never actually get around to doing it...the difficulty of actually seeing a work through to com...

Kobo Soft Launch of Rise to Revolt

A basic canard of the writing craft (at least according to the indie author websites that I have been reading for years) is that you can only polish a turd for so long. A book can only be edited for so long before it becomes a waste of the time and energy that could be better spent writing the next book. Rise to Revolt is my first completed book, I have poured years of on-again, off again effort into building the universe and sketching out the narrative that I intend to tell. As a first book, it is going to be the weakest book that I produce, simply by virtue of being  the first book. Every author must start somewhere, and I strongly feel that Rise to Revolt is the very best work that I am capable of producing right now, and that it is a work that is worth reading. Ultimately however, you as the reader must be the judge of that, and I would be lying if I didn't admit to a certain amount of nervousness at the prospect. Rise to Revolt is the first in a trilogy of book...