In this section, you'll have a chance to practice the concepts you've learned in the videos. First, review the core concepts covered that you'll need to keep in mind. Then go through the exercises below.
Remember, these are for your own benefit. Feel free to skip them if you don't find a particular exercise valuable or you get stuck for too long.
When working with an application that uses external packages, you need to communicate what packages are required for it to run. We do this with a requiements.txt
file, here is an example:
colorama
prompt_toolkit
Once you have a virtual environment active, you can install all the dependencies with this command:
(env) C:\> pip install -r requirements.txt
Virtual environments are key to having different versions of the same library coexisting on your computer. You create one as follows:
$ python3 –m venv venv
$ . venv/bin/activate
C:\> python –m venv venv
C:\> venv\scripts\activate
Pip is the tool you use on the command line to install and view external packages. Here are some examples:
$ pip list
$ pip install colorama
$ pip install -r requirements.txt
$ pip uninstall requests
Now it's your turn. In this practice, go back to the tic tac toe game we created back in the chapter on problem solving. Alternatively, if you made it through Connect 4, you can work with that one instead. Your job will be to:
- Create a virtual environment.
- Set it as the active python interpreter in PyCharm under
settings > project > project interpreter
. - Create a requirements.txt file with
colorama
as a dependency. - Install the requirements with
pip
. - Use
colorama
to add colored output to your game.