Complete Roguelike Tutorial, using python3+libtcod, setup Mac
This is part of a series of tutorials; the main page can be found here.
Installing an Editor
Editors are often a personal choice. Their primary function is to allow the creation and editing of code. Additional functionality may be included such as code intelligence, code completion, static analysis, testing, debugging, etc. usually through plugins. Some editors are also IDEs or integrated development environments. They can help manage the lifetime of a project. For this tutorial, you only need an editor and none of the extra functionality, but an IDE may be very helpful when learning programming (or Python) for the first time.
The following editors are all excellent for python development. You only need one.
Note that these are listed in order of decreasing preference for development with python as a beginner. (i.e. pick one of the top ones for the best out of the box python experience)
Setting up Bash
Open finder (cmd + space) and go to your home folder and then press CMD + SHIFT + . (command + shift + period). Look for a ".bashrc" file within finder. Open it up in your editor or create a new file. Make sure the following lines show up at the bottom of the file:
Opening a Terminal
While Mac comes with a Terminal built-in, Iterm2 is the recommend install for a terminal. Once installed, simply press `Cmd + Space Bar` and type in iterm or terminal (for the default mac terminal). Whether you've installed iterm or are using the default terminal, we will use the word "terminal" below to refer to your preferred program (iterm or terminal).
Setting up Homebrew
Homebrew is a package manager for Mac. Within a terminal, type the following to install homebrew:
Setting up Python
To install the latest python version, simply run within a terminal:
To validate that we've installed python correctly, within a terminal, run:
The version should be at least "Python 3.7.0" (See: Release Schedule).
Environmental Variable: Path
Brew installs python into /usr/local/opt/python. You may need to add the following line to your $HOME/.bash_profile file and then restart your terminal. Do not add this line to your .bashrc file as this will invariably cause issues with subprocesses.
Python 3 comes bundled with a python package manager called `pip` which is used to install all project related python dependencies. To make sure we have `pip` installed run in a terminal:
Setting up your Project
Creating a virtual environment
Most python developers will use a virtual environment to isolate python and any project related dependencies from being installed into the system. This practice is a safety measure to prevent a developer's computer from becoming unstable and is highly recommended.
Vsh is a virtual environment generation tool. This will help you manage and build virtual environments. Most python developers will use a virtual environment to isolate their projects from their system. Additionally, vsh runs the python virtualenv in a sub-process shell To install:
Creating a virtual environment using vsh
To create a new virtual environment with python 3 for our project, just use the following:
You should now be in your virtual environment
To make sure, test your python version. You should see something like version "3.7.0". Note that the version number and virtual env name is also in the command-line prompt
Installing libtcod into our project
Validate that we have libtcod installed.
Our first roguelike will be run entirely from a single file, firstrl.py. However, to support some future needs regarding packaging and to make development easier, we need to add our dependencies into the project folder.
When we're all done, the basic folder structure should look like this:
You're ready to start editing firstrl.py!
Now you're ready to start writing code.