“Run the App” Exercise (Tic Tac Toe)
In this exercise, we’ll practice downloading, configuring, and running an existing Python application.
We’ll discuss topics related to command line computing, Anaconda virtual environments, Python package management, and environment variables.
Instructions
- Visit this “Tic Tac Toe” repository on GitHub. This repository contains a simple command-line game. We’ll refer to this repository as the “upstream” remote repository.
- Click the “Fork” button (top right of the page) to make a copy of the repo under your own control. We’ll refer to your forked copy as the “origin” remote repository.
- Follow the instructions in the repository’s “README.md” file to install, setup and run the Python code contained inside:
- Click the green button on GitHub to “Clone”, or download, your remote fork. Choose the GitHub Desktop option, selecting the “for my own purposes” option, if prompted by GitHub Desktop. When prompted where to download it, choose a familiar location like the Desktop. We’ll refer to this as the “local repository”.
- Use the finder or file explorer to verify you have downloaded the files and they exist, for example on your Desktop.
- Use the command-line to navigate to the local repository (using one or more
cd
commands). - Use the
conda
utility to create a new virtual environment with the specified version of Python, then activate the virtual environment. - Use the
pip
utility to install any required third-party packages specified in the repo’s “requirements.txt” file. - Use the
python
utility to run the Python file(s) as described in the README’s “Usage” section.
Success Criteria
Once you have played a single game, you will have succeeded.
For fun, try replaying the game against different kinds of opponents (computer, human, etc.).
Further Exploration
Optionally simulate many games between computer players, and see the CSV file of game outcomes that gets produced.
Practice passing environment variables to customize the game count and player types.
Troubleshooting & Help
Here are some common errors you may run into while trying to run Python apps locally.
Bad Anaconda Installation
If you try to run a conda
command, and you see an error like “conda: command not found”, it means there’s something wrong with your installation.
It’s OK. Feel free to reach out to an instructor and ask for help. See also these known troubleshooting remedies.
We will probably have to ask where anaconda
in the Anaconda Prompt program to learn where your Anaconda installation resides, then issue a corresponding command like ~/anaconda3/Scripts/conda init bash
in Git Bash to fix the issue. Then close and re-open Git Bash for the changes to take effect.
Forgot to Install Packages
If you see an error like “ModuleNotFoundError: No module named ‘…’”, it’s because the given package isn’t installed, so run the pip install -r requirements.txt
command from the repository’s root directory to ensure that package has been installed into the virtual environment, before trying to run the app again.