Sunday, June 18, 2017

Installing Pygame on windows

As explained in my Summer of code 2017: Python post I decided to pick up Python. As explained in that post my son wants to do some game development. with Python you can use Pygame to do game development.

My first attempt to install Pygame didn't end well, the instructions I found were to were to download the pygame wheel file, rename the .whl file to .zip. After that extracting the files into a folder. Then you had to move the header files into the \Python36\include folder. Another thing I had to do was moving the pygame folder and the pygame-1.9.3.dist-info folder into the \Python36\Lib\site-packages folder

After that was done, I got some strange errors, something about init() missing (AttributeError: module 'pygame' has no attribute 'init')

Another option was to use pip

I tried that

C:\Users\dgobo>pip install pygame
Collecting pygame
  Downloading pygame-1.9.3-cp36-cp36m-win_amd64.whl (4.2MB)
    100% |████████████████████████████████| 4.2MB 234kB/s
Installing collected packages: pygame
Successfully installed pygame-1.9.3

I still had an error after this was done

I noticed that pip installed Pygame into the following folder


Hmmm... what is anaconda and why did pip install Pygame there?

I then navigated to the Python directory, instead of pip install pygame I did python -m pip install pygame

C:\Python36>python -m pip install pygame
Collecting pygame
  Using cached pygame-1.9.3-cp36-cp36m-win_amd64.whl
Installing collected packages: pygame
Successfully installed pygame-1.9.3

That did it, after that ran, I had no errors anymore

So all you have to do pip from python, not by itself

Hopefully this will help someone if they run into this issue

1 comment:

Peter Schott said...

PIP gave me fits before I really understood that it was a command line util. I appreciate you showing how to call it from within Python if it's installing into the wrong Python setup. I figure that has to have something to do w/ path order, but forcing it into a given install will be helpful.