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 s

Lazy Inventory 0.4 Released

LAZY INVENTORY RELEASE 0.4 OVERVIEW I am proud to announce the 0.4 release of Lazy Inventory, the amazing inventory management system that nobody currently uses ;) It can be downloaded via clicking this link . In the last few months I have made quite a bit of progress on adding new features and debugging existing ones, as well as moving to a numbered release system for easier tracking. We are a long ways away from even a 1.0 release, but Lazy Inventory 0.4 now is fully capable of not only managing inventory for a small business, but also picking orders. I would say it's an even bigger jump from trying to use Google Sheets or Excel than the retroactively renamed version 0.1 was. My very basic features and bug tracking spreadsheet is shown at the right, its pretty basic but it gets the job done and keeps me on track. Currently there are forty-four features on my to-do list, a version 1.0 release will require somewhere around  thirty-five of them to be completed and polishe