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

Those Violent Amish

Three men are dead in Fresno, after a man named Kori Ali Muhammad opened fire, hitting four white men in total and killing three of them. He is also suspected of the murder of a security guard this past Thursday.  A survey of his Twitter shows him using the well known Amish hate phrase " Allahu Akbar. " Not that you would know that from the AP, as they said that he was instead shouting "God is great" as he went on his murderous rampage.  True that is a rough  approximation of what the phrase means, but I am reasonably sure that everybody these days knows who is likely to be shouting that phrase as they murder the innocent.  It's the Amish of course.  Anything to further obfusticate the facts of the case and push the Narrative of Muslims(I mean Amish) as peace-loving, misunderstood individuals, not like those violent Christians who go to church on Sunday where they plot to further their terroristic reign over the world.  ABC is now ...

Writing Update

So far this week I haven't gotten too much done, I've mostly been outlining. Book 1 was fully outlined in basic one sentence form, so I have been going back through the outline and tightening it up, by removing things that impede the narrative flow, and expanding the areas that help it progress.  I want to make sure that I don't have anything outlined that is just "filler" or something clearly thrown in just to pad the word count a bit, I hate it when authors do that. The goal is to get each one sentence outline expanded to a full paragraph. Then I'll do a scene breakdown, then and only then will I write the story. My hope is that this will not only keep the books feeling cohesive, but will also help me use my writing time more effectively. The outline for The Pyongyang Incursion  is twenty-one points currently, and I have expanded nine of them to a full paragraph in the last week. I also have the first three outline points done on the sequel, The Vladi...

Axis and Allies 1942 Online Review

I have been enjoying Axis and Allies for almost twenty years now. I started with what is now called Axis and Allies Classic, the 1984 edition. I bought it for forty dollars (plus eight dollars shipping and handling) when I was about twelve. I had played the game at a neighbor's house, and absolutely fell in love with it, obsessing over it and mentally playing and replaying games in my head, trying to understand its ins and outs. I read the strategy guide, looked for opportunities to try new strategies, and even built a custom table for the game, something that barely fit into the cramped room my brother and I shared. I never became an expert in A&A, at best I am a fairly good casual player and the nice thing about A&A is that you don't have to be a massive board game nerd to enjoy it. The rules are complex, but the basics are easy to grasp. Once I went off to college, it was years before I played another A&A game, and in that time there had been a couple rev...