I'm very new to python but I'd like to learn it by making games and pygame seems to be the best option. Since PyPy is the fastest implementation of python (I think) I decided to use that one. But I have no idea how to get those two working together.
I'm on windows.
If anyone would be so kind to give me a step by step on what I need to do I'd be really grateful.
So far, I've installed (extracted to a folder) PyPy, set the pypy.exe as the default for opening .py files, installed Pygame and tried running one of the example .py files. I get the "module pygame not found" error with the first import line in the file.
PyPy supports Python 2.7. PyPy3, released in beta, targets Python 3.
You can download 64-bit pygame for Windows but not for Mac.
Pygame is a library that helps us create games using Python. Pygame uses SDL (short for Simple DirectMedia Layer) which helps us get access to the keyboard, mouse, and graphics. Pygame runs on almost every platform. This guide shows you how to import Pygame in Visual Studio Code.
Pygame on Python 3.8 You should use the same command you use to run a Python terminal session on your system, which might be python , python3 , py , python3. 8 , or something else. If you've had any issues running Pygame on macOS, this version of Pygame should address those issues as well.
pygame isn't compatible with pypy, so to use it you'll have to stick with cPython.
Update (April 2018):
As pointed out by in this answer the PyPy v6.0 release now works with pygame - although not yet with the current stable (pygame 1.9.3) release, but with the current developement branch (1.9.4.dev0).
tested on ubuntu 17.10 by:
sudo apt build-dep python-pygame
./bin/pypy3 -m ensurepip
./bin/pypy3 -m pip install 'Pygame>=1.9.4.dev0'
./bin/pypy3 -m pygame.examples.aliens
Works for both the pypy3 and pypy2 versions.
Pygame games actually spend very little of their time running python code. The vast, vast majority is spent doing SDL fill
and flip
operations. Most fill
s are unnecessary. How important is this? Well, take my computer. Say you write a game that has a loop that just paints the background one color. It will get about 40 fps. This is because it's basically going to every pixel individually and writing to it. This is using 200 x 300 = 60000 operations every frame to do nothing.
So instead of painting the entire background, just paint the parts that were drawn on the previous frame.
This makes your code a bit more complicated, but it produces a huge performance increase.
Also, don't forget to run cProfile to see where the problem areas are. Look, don't guess.
It looks like PyPy v6 (April 2018) will improve the situation and make PyPy compatible with PyGame and other C python extensions. See https://renesd.blogspot.co.uk/2018/03/pygame-on-pypy-usable.html for an example.
We currently don't have binaries for PyPy on the package index yet. So you need to compile pygame from source, rather than just using pip to install pygame.
Get a PyPy version 6+ (or download a nightly one).
The instructions for compiling from source on windows can be used: https://www.pygame.org/wiki/CompileWindows
Just use the pypy3
binary instead of the python
one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With