Learning objectives
- Create a dedicated conda environment for the curriculum.
- Install Python and key packages in that environment.
- Activate and use the environment for running exercises.
Why use a conda environment?
A conda environment isolates the curriculum’s Python and packages from your system or other projects. You can use a specific Python version and install NumPy, PyTorch, Gym, etc. without affecting other work. If something breaks, you can recreate the environment.
Steps
Install Miniconda or Anaconda (if not already installed). Miniconda is minimal; Anaconda includes more packages and an IDE. Download from docs.conda.io.
Create an environment (e.g. named
rl):1conda create -n rl python=3.10Activate the environment:
- Linux/macOS:
conda activate rl - Windows:
conda activate rl(in Anaconda Prompt or terminal that has conda in PATH)
- Linux/macOS:
Install packages:
1 2 3conda install numpy matplotlib pip install gym # or pip install gymnasium pip install torch # for PyTorch (or use conda install pytorch)See Installing Libraries for more options (TensorFlow, etc.).
Run your scripts or Jupyter from this environment so they use the correct Python and packages.
Deactivate when done:
conda deactivate
Tips
- To use this environment in Jupyter:
pip install ipykernelthenpython -m ipykernel install --user --name rl --display-name "Python (rl)". Then choose the “Python (rl)” kernel in Jupyter. - To remove the environment later:
conda env remove -n rl
See Setting Up Your Environment for a pre-install check and Installing Libraries for package details.