Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
<ph type="x-smartling-placeholder">
Suivez ces instructions pour installer le SDK et l'exemple de code dans votre projet. Exécuter
toutes les commandes de cette page dans un terminal de l'appareil (soit directement
ou via une connexion SSH).
Configurer un nouvel environnement virtuel Python
utiliser un environnement virtuel Python ;
pour isoler le SDK et ses dépendances des packages Python du système.
(Recommandé) Pour Python 3:
sudo apt-get updatesudo apt-get install python3-dev python3-venv # Use python3.4-venv if the package cannot be found.python3 -m venv envenv/bin/python -m pip install --upgrade pip setuptools wheelsource env/bin/activate
Le package du SDK de l'Assistant Google contient tout le code nécessaire pour obtenir
Assistant Google exécuté sur l'appareil, y compris l'exemple de code.
Générez des identifiants pour pouvoir exécuter l'exemple de code et les outils. Références
le fichier JSON que vous avez téléchargé à l'étape précédente ;
vous devrez peut-être le copier sur l'appareil. Ne renommez pas ce fichier.
Please visit this URL to authorize this application: https://...
Copiez l'URL et collez-la dans un navigateur (vous pouvez le faire sur n'importe quel ordinateur).
Vous êtes alors invité à vous connecter à votre compte Google. Signer
au compte Google qui a créé le projet de développeur à l'étape précédente
étape.
Une fois que vous aurez approuvé la demande d'autorisation de l'API, un code apparaîtra
dans votre navigateur ("4/XXXX", par exemple). Copiez et collez ce code dans la
terminal:
Enter the authorization code:
Si l'autorisation aboutit, une réponse semblable à la suivante s'affiche :
les éléments suivants:
Si InvalidGrantError s'affiche à la place, cela signifie qu'un code non valide a été saisi.
Réessayez en prenant soin de copier et coller l'intégralité du code.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/26 (UTC).
[null,null,["Dernière mise à jour le 2025/07/26 (UTC)."],[[["\u003cp\u003eThis guide provides instructions for installing the Google Assistant SDK and sample code on your device using Python.\u003c/p\u003e\n"],["\u003cp\u003eThe setup involves configuring a Python virtual environment, installing necessary dependencies, and getting the Google Assistant SDK package.\u003c/p\u003e\n"],["\u003cp\u003eUsers need to generate credentials to authorize the sample code to access the Google Assistant API.\u003c/p\u003e\n"],["\u003cp\u003eThe guide is specifically for the deprecated Google Assistant Library for Python; the Google Assistant Service is recommended instead.\u003c/p\u003e\n"]]],[],null,["# Install the SDK and Sample Code\n\n| **Warning:** The Google Assistant Library for Python is deprecated as of June 28th, 2019. Use the [Google Assistant Service](/assistant/sdk/guides/service/python) instead.\n\n\u003cbr /\u003e\n\nFollow these instructions to install the SDK and sample code on your project. Run\nall of the commands on this page in a terminal on the device (either directly\nor via an SSH connection).\n\nConfigure a new Python virtual environment\n------------------------------------------\n\nUse a [Python virtual environment](https://docs.python.org/3/library/venv.html)\nto isolate the SDK and its dependencies from the system Python packages.\n| **Note:** For the Raspberry Pi, run the following commands from the `/home/pi` directory.\n\n(Recommended) For Python 3: \n\n sudo apt-get update\n sudo apt-get install python3-dev python3-venv # Use python3.4-venv if the package cannot be found.\n python3 -m venv env\n env/bin/python -m pip install --upgrade pip setuptools wheel\n source env/bin/activate\n\nFor Python 2.7: \n\n sudo apt-get update\n sudo apt-get install python-dev python-virtualenv\n virtualenv env --no-site-packages\n env/bin/python -m pip install --upgrade pip setuptools wheel\n source env/bin/activate\n\nGet the package\n---------------\n\nThe Google Assistant SDK package contains all the code required to get the\nGoogle Assistant running on the device, including the sample code.\n\nInstall the package's system dependencies: \n\n```\nsudo apt-get install portaudio19-dev libffi-dev libssl-dev libmpg123-dev\n```\n\n\u003cbr /\u003e\n\nUse `pip` to install the latest version of the [Python package](https://pypi.python.org/pypi/google-assistant-library)\nin the virtual environment: \n\n```\npython -m pip install --upgrade google-assistant-library==1.0.1\n``` \n\n```\npython -m pip install --upgrade google-assistant-sdk[samples]==0.5.1\n```\n\n\u003cbr /\u003e\n\nGenerate credentials\n--------------------\n\n1. Install or update the authorization tool:\n\n ```\n python -m pip install --upgrade google-auth-oauthlib[tool]\n ```\n\n \u003cbr /\u003e\n\n2. Generate credentials to be able to run the sample code and tools. Reference\n the JSON file you downloaded in a previous [step](/assistant/sdk/guides/library/python/embed/register-device#download-credentials);\n you may need to copy it the device. Do not rename this file.\n\n ```\n google-oauthlib-tool --scope https://www.googleapis.com/auth/assistant-sdk-prototype \\\n --scope https://www.googleapis.com/auth/gcm \\\n --save --headless --client-secrets /path/to/client_secret_client-id.json\n ```\n\n You should see a URL displayed in the terminal: \n\n ```\n Please visit this URL to authorize this application: https://...\n ```\n\n \u003cbr /\u003e\n\n3. Copy the URL and paste it into a browser (this can be done on any machine).\n The page will ask you to sign in to your Google account. Sign\n into the Google account that created the developer project in the previous\n [step](/assistant/sdk/guides/library/python/embed/config-dev-project-and-account#config-dev-project).\n\n | **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.\n4. After you approve the permission request from the API, a code will appear\n in your browser, such as \"4/XXXX\". Copy and paste this code into the\n terminal:\n\n ```\n Enter the authorization code:\n ```\n\n If authorization was successful, you will see a response similar to\n the following: \n\n ```\n credentials saved: /path/to/.config/google-oauthlib-tool/credentials.json\n ```\n\n If instead you see `InvalidGrantError`, then an invalid code was entered.\n Try again, taking care to copy and paste the entire code.\n | **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.\n\nNext step\n---------\n\n[Run the Sample Code](/assistant/sdk/guides/library/python/embed/run-sample)"]]