# Install the SDK and Sample Code

> [!WARNING]
> **Warning:** The Google Assistant Library for Python is deprecated as of June 28th, 2019. Use the [Google Assistant Service](https://developers.google.com/assistant/sdk/guides/service/python) instead.

<br />

Follow these instructions to install the SDK and sample code on your project. Run
all of the commands on this page in a terminal on the device (either directly
or via an SSH connection).

## Configure a new Python virtual environment

Use a [Python virtual environment](https://docs.python.org/3/library/venv.html)
to isolate the SDK and its dependencies from the system Python packages.

> [!NOTE]
> **Note:** For the Raspberry Pi, run the following commands from the `/home/pi` directory.

(Recommended) For Python 3:

    sudo apt-get update
    sudo apt-get install python3-dev python3-venv # Use python3.4-venv if the package cannot be found.
    python3 -m venv env
    env/bin/python -m pip install --upgrade pip setuptools wheel
    source env/bin/activate

For Python 2.7:

    sudo apt-get update
    sudo apt-get install python-dev python-virtualenv
    virtualenv env --no-site-packages
    env/bin/python -m pip install --upgrade pip setuptools wheel
    source env/bin/activate

## Get the package

The Google Assistant SDK package contains all the code required to get the
Google Assistant running on the device, including the sample code.

Install the package's system dependencies:

```
sudo apt-get install portaudio19-dev libffi-dev libssl-dev libmpg123-dev
```

<br />

Use `pip` to install the latest version of the [Python package](https://pypi.python.org/pypi/google-assistant-library)
in the virtual environment:

```
python -m pip install --upgrade google-assistant-library==1.0.1
```

```
python -m pip install --upgrade google-assistant-sdk[samples]==0.5.1
```

<br />

## Generate credentials

1. Install or update the authorization tool:

   ```
   python -m pip install --upgrade google-auth-oauthlib[tool]
   ```

   <br />

2. Generate credentials to be able to run the sample code and tools. Reference
   the JSON file you downloaded in a previous [step](https://developers.google.com/assistant/sdk/guides/library/python/embed/register-device#download-credentials);
   you may need to copy it the device. Do not rename this file.

   ```
   google-oauthlib-tool --scope https://www.googleapis.com/auth/assistant-sdk-prototype \
         --scope https://www.googleapis.com/auth/gcm \
         --save --headless --client-secrets /path/to/client_secret_client-id.json
   ```

   You should see a URL displayed in the terminal:

   ```
   Please visit this URL to authorize this application: https://...
   ```

   <br />

3. Copy the URL and paste it into a browser (this can be done on any machine).
   The page will ask you to sign in to your Google account. Sign
   into the Google account that created the developer project in the previous
   [step](https://developers.google.com/assistant/sdk/guides/library/python/embed/config-dev-project-and-account#config-dev-project).

   > [!NOTE]
   > **Note:** To use other accounts, first [add those accounts](https://cloud.google.com/iam/docs/granting-changing-revoking-access) to your Actions Console project as Owners.

4. After you approve the permission request from the API, a code will appear
   in your browser, such as "4/XXXX". Copy and paste this code into the
   terminal:

   ```
   Enter the authorization code:
   ```

   If authorization was successful, you will see a response similar to
   the following:

   ```
   credentials saved: /path/to/.config/google-oauthlib-tool/credentials.json
   ```

   If instead you see `InvalidGrantError`, then an invalid code was entered.
   Try again, taking care to copy and paste the entire code.

   > [!NOTE]
   > **Note:** The authorization tool creates a new `credentials.json` file in a hidden `.config` directory on the device. This file contains an access token that is used to call the Google Assistant API.

## Next step

[Run the Sample Code](https://developers.google.com/assistant/sdk/guides/library/python/embed/run-sample)