{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "origin_pos": 0
   },
   "source": [
    "# Installation\n",
    ":label:`chap_installation`\n",
    "\n",
    "In order to get you up and running for hands-on learning experience,\n",
    "we need to set you up with an environment \n",
    "for running Python, Jupyter notebooks, the relevant libraries, \n",
    "and the code needed to run the book itself.\n",
    "\n",
    "## Installing Miniconda\n",
    "\n",
    "The simplest way to get going will be to install\n",
    "[Miniconda](https://conda.io/en/latest/miniconda.html). \n",
    "The Python 3.x version is required. \n",
    "You can skip the following steps \n",
    "if your machine already has conda installed.\n",
    "\n",
    "Visit the Miniconda website and determine \n",
    "the appropriate version for your system\n",
    "based on your Python 3.x version and machine architecture.\n",
    "For example, if you are using macOS and Python 3.x \n",
    "you would download the bash script \n",
    "whose name contains the strings \"Miniconda3\" and \"MacOSX\",\n",
    "navigate to the download location,\n",
    "and execute the installation as follows:\n",
    "\n",
    "```bash\n",
    "sh Miniconda3-latest-MacOSX-x86_64.sh -b\n",
    "```\n",
    "\n",
    "A Linux user with Python 3.x \n",
    "would download the file\n",
    "whose name contains the strings \"Miniconda3\" and \"Linux\" \n",
    "and execute the following at the download location:\n",
    "\n",
    "```bash\n",
    "sh Miniconda3-latest-Linux-x86_64.sh -b\n",
    "```\n",
    "\n",
    "Next, initialize the shell so we can run `conda` directly.\n",
    "\n",
    "```bash\n",
    "~/miniconda3/bin/conda init\n",
    "```\n",
    "\n",
    "Now close and reopen your current shell. \n",
    "You should be able to create \n",
    "a new environment as follows:\n",
    "\n",
    "```bash\n",
    "conda create --name d2l python=3.8 -y\n",
    "```\n",
    "\n",
    "## Downloading the D2L Notebooks\n",
    "\n",
    "Next, we need to download the code of this book. \n",
    "You can click the \"All Notebooks\" tab \n",
    "on the top of any HTML page \n",
    "to download and unzip the code.\n",
    "Alternatively, if you have `unzip` \n",
    "(otherwise run `sudo apt install unzip`) available:\n",
    "\n",
    "```bash\n",
    "mkdir d2l-en && cd d2l-en\n",
    "curl https://d2l.ai/d2l-en.zip -o d2l-en.zip\n",
    "unzip d2l-en.zip && rm d2l-en.zip\n",
    "```\n",
    "\n",
    "Now we can activate the `d2l` environment:\n",
    "\n",
    "```bash\n",
    "conda activate d2l\n",
    "```\n",
    "\n",
    "## Installing the Framework and the `d2l` Package\n",
    "\n",
    "Before installing any deep learning framework, \n",
    "please first check whether or not \n",
    "you have proper GPUs on your machine\n",
    "(the GPUs that power the display \n",
    "on a standard laptop are not relevant for our purposes).\n",
    "If you are working on a GPU server,\n",
    "proceed to :ref:`subsec_gpu` \n",
    "for instructions on how \n",
    "to install GPU-friendly versions\n",
    "of the relevant libraries.\n",
    "\n",
    "If your machine does not house any GPUs,\n",
    "there is no need to worry just yet.\n",
    "Your CPU provides more than enough horsepower \n",
    "to get you through the first few chapters.\n",
    "Just remember that you will want to access GPUs \n",
    "before running larger models.\n",
    "To install the the CPU version,\n",
    "execute the following command.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "origin_pos": 3,
    "tab": [
     "tensorflow"
    ]
   },
   "source": [
    "You can install TensorFlow with both CPU and GPU support as follows:\n",
    "\n",
    "```bash\n",
    "pip install tensorflow tensorflow-probability\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "origin_pos": 4
   },
   "source": [
    "Our next step is to install \n",
    "the `d2l` package that we developed \n",
    "in order to encapsulate\n",
    "frequently used functions and classes\n",
    "found throughout this book.\n",
    "\n",
    "```bash\n",
    "# -U: Upgrade all packages to the newest available version\n",
    "pip install -U d2l\n",
    "```\n",
    "\n",
    "Once you have completed these installation steps, we can the Jupyter notebook server by running:\n",
    "\n",
    "```bash\n",
    "jupyter notebook\n",
    "```\n",
    "\n",
    "At this point, you can open http://localhost:8888 \n",
    "(it may have already opened automatically) in your Web browser. \n",
    "Then we can run the code for each section of the book.\n",
    "Please always execute `conda activate d2l` \n",
    "to activate the runtime environment\n",
    "before running the code of the book \n",
    "or updating the deep learning framework or the `d2l` package.\n",
    "To exit the environment, \n",
    "run `conda deactivate`.\n",
    "\n",
    "\n",
    "## GPU Support\n",
    ":label:`subsec_gpu`\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "origin_pos": 6,
    "tab": [
     "tensorflow"
    ]
   },
   "source": [
    "By default, the deep learning framework is installed with GPU support.\n",
    "If your computer has NVIDIA GPUs and has installed [CUDA](https://developer.nvidia.com/cuda-downloads),\n",
    "then you are all set.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "origin_pos": 7
   },
   "source": [
    "## Exercises\n",
    "\n",
    "1. Download the code for the book and install the runtime environment.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "origin_pos": 10,
    "tab": [
     "tensorflow"
    ]
   },
   "source": [
    "[Discussions](https://discuss.d2l.ai/t/436)\n"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}