Lab 0 - Intro
Lab 0 - Intro
2024
Reinforcement Learning – Faraz Janan
Version 1.1
Running Python
There are a number of ways in which Python can be installed and run. Linux comes
with its own version of Python 3 installed: open a terminal window and run the
command python3. To exit Python commands, enter quit(). Linux comes with both a
Python 2 and Python 3 versions. We will be working in Python 3, using the pip package
manager.
We can enhance the base Python installation with whichever libraries we choose.
However, it is good practice to set up and run scripts in separate virtual environments
for projects that require different libraries and packages to avoid possible dependency
clashes.
Start by updating your package manager, run: python3 -m pip install --user --upgrade
pip. Create a virtual environment called rl by using the command python3 -m venv rl.
A directory rl will be created containing files relevant to this new virtual environment.
Next, activate the environ- ment by running the command source rl/bin/activate. You
should now see (rl) in front of your username in the terminal window. Now, any
modifications or package installations you carry out will be applied only to rl rather
than the base environment.
Install the numpy and matplotlib libraries by running pip install numpy matplotlib.
Once it has completed, run python3 and try to import numpy to check the installation
was successful.
Notebooks
The Jupyter package will allow you to run interactive notebooks in which you can run
Python code. Run pip install jupyter to install Jupyter. Once it is done, try to launch a
notebook by running
jupyter notebook. Check that you can import the numpy and matplotlib modules in your
notebook. You may have to run the command python3 -m ipykernel install --user --
name=rl to include the packages from your rl environment in the notebook. After you
do this, restart the jupyter notebook and after opening a new notebook you should see
the option to change to your virtual environment under the ‘Kernel’ menu options.
Later on in the course, you will be required to install other packages (mainly PyTorch
and OpenAI Gym), which you will be able to install similarly.
Another resource you may find useful in alternative to Jupyter notebooks are Colab
notebooks. This allows you to run code remotely and potentially use powerful GPUs.
Check the page
https://colab.research.google.com/ to investigate this alternative.