09 Jan 2023 - TUNING DIPSW (Andrew Hsu)
« Prev: #0: The heart
Good day. In this series of articles, I’ll be attempting to program a simple 2D fighting game using the Python game development library Pygame.
Even after sitting through the previous article, we still have a bit of preparation to complete before we can get started. Let’s get our prerequisites sorted out.
https://www.python.org/downloads/
(2023/2/13) The original Pygame library was only compatible with Python 3.10, forcing users to download a less-recent version of Python, but the Pygame community edition library that has taken its place is compatible with Python 3.11.
Confirm the installation by running
python3 --version
in a terminal.
'python' is not recognized as an internal or external command, operable program or batch file.
You might run into your first error here. Don’t panic, errors are going to happen a lot.
--
Whatever the case, here’s some of the basic steps you should try to solve an error:
Advice for this error on Windows, if you can’t figure it out:
On Windows, this is usually caused by the location of the newly-installed Python executable being absent from the PATH environment variable. Try searching for "how to add python path environment variable windows". You may also need to restart your computer for the environment variable changes to take effect.
The latter two are a bit lengthy and harsh to the reader, but if you’re willing to swallow your pride, all three of these articles teach you best practices for how to ask for help in a way that will improve your chances of getting a good answer.
I recommend giving them a read when you have a bit of time.
Due to issues with the original Pygame project being able to update to Python 3.11 compatibility, a new fork of the Pygame project, pygame-community, has been adopted to support Python 3.11 and more frequent updates.
Installation is pretty straightforward:
pip install pygame-ce
You can uninstall the original pygame if you had it installed; you should not need to adjust any other files.
pip uninstall pygame
Again, as a sanity check, try getting a quick program to work. You might need to install an IDE first, though:
As mentioned in #0, don’t settle for accepting pain points, try to eliminate or reduce them however you can. An IDE (Integrated Development Environment) should be the program you write most, if not all of your code in, as they provide much-needed quality-of-life features (eg. text autocompletion, bracket highlighting, test runners plugins, Git integration) for development. I recommend Visual Studio Code, an excellent, free pick with robust support from its developers and plugin writers.
Another option I found for Python is Spyder IDE + Anaconda. I haven’t tried this myself, but it was recommended to me by another Pygame tutorial I found very helpful.
Some optional settings or plugins you might like to set up at this point include a linter or a type checker.
You don’t need to set up VCS to write code, but having it set up will help you keep track of your project changes. There are a number of VCS options out there, but Git is the one I’m familiar with.
I would consider having the ability to do all of these an integral part of development QOL. Better to have it and not need it than the other way around, after all.
Git can be intimidating to learn due to the combination of having a very long command list available and being invoked through the command line*, but these are things that can be overcome. Take a bit of time, learn something new, and you’ll have a handy new tool in your toolbox.
Here is a summary of the basic Git workflow most of your Git usage will resemble:
# In the root of your project folder, generate a Git repository # Only need to do this once git init # Get a look at the list of changed/uncommitted files git status # Add a single file to the list of files to be committed git add filename.txt # OR Use a pattern and the wildcard * to add all files starting with "filename." # to the list of files to be committed git add filename.* # OR What the heck, add all files git add . # Look again, check which files have been staged git status # Ok, not that file, put that one back # Unstage this file from the list of files to be included in the next commit # Maybe write a .gitignore file to automatically prevent this one from ever getting added git restore --staged passwords.txt # Tie it all up in a bow with a message git commit -m "Descriptive message summarizing this chunk of changes" # View the newly-updated commit log for your sanity git log
Some other useful commands include:
# Split into a new development branch (eg. for experimental feature # or a new version release) # For your personal work, you might not need this, but it is an option git branch git branch list git checkout # Revert to last commit, saving all uncommitted changes away # on an invisible stack saved by Git git stash # Put the last-stashed set of changes back into play, popping it off # the stack of set-of-changes stored by Git git stash pop # Quickly undo all uncommitted changes to a file # Overlaps with the command to unstage a file from the list of files to be included in a commit # just with no --staged flag, try very hard to avoid using this accidentally # ! This can erase all your changes even if saved, and can't be undone through Git, be VERY careful git restore filename.txt # Read more about this and soft/hard reverts at your own leisure git revert
Excellent. The necessary software has been installed, and your dev tools are all in place. You’re ready to write some code.
Let’s get started.
…Next time.
» Next: #0.8: Rollback (pre-reading)