安装
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
无论您是从 PyPI 安装该库还是从 GitHub 克隆该库,我们都建议您使用有效的虚拟环境执行以下步骤。如需了解如何创建和激活虚拟环境,请参阅虚拟环境文档。
从 PyPI 安装模块
该库在 PyPI 上分发,可以使用 pip 通过以下命令进行安装:
python -m pip install google-ads
从 GitHub 安装库
您可以从 GitHub 将库的源代码克隆到本地机器上。克隆源代码有助于轻松执行示例或开发库本身。作为参考,运行其中一个身份验证示例是配置库以供使用的必要步骤。
确保您的环境中存在 python3.8
或更高版本。
最简单的方法是使用 pyenv
:
pyenv local 3.8
从 GitHub 克隆客户端库:
git clone git@github.com:googleads/google-ads-python.git
进入代码库并安装:
cd google-ads-python
python -m pip install .
如果您打算开发该库,请在进行任何更改之前和之后运行单元测试:
确保您的环境中包含所有受支持的 Python 语言版本。使用 pyenv
:
pyenv local 3.8 3.9 3.10 3.11 3.12
安装库的特定于测试的依赖项:
python -m pip install .[tests]
运行单元测试,确保库正常运行:
nox
可选:也可以使用 Docker 运行单元测试。首先,您必须安装 Docker。然后,从 google-ads-python
目录运行以下命令:
docker build -t google-ads-python:test .
docker run -it google-ads-python:test nox
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[[["\u003cp\u003eThe Google Ads Python library can be installed from PyPI using pip with the command \u003ccode\u003epython -m pip install google-ads\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo install from GitHub, clone the repository, navigate into it, and run \u003ccode\u003epython -m pip install .\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEnsure you have Python 3.8 or later installed in your environment, potentially using pyenv.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should run unit tests before and after making changes, utilizing nox or Docker for execution.\u003c/p\u003e\n"],["\u003cp\u003eFor library setup and usage, refer to the Virtual Environment and authentication example documentation.\u003c/p\u003e\n"]]],[],null,["# Installation\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nWhether you're installing the library from PyPI or cloning it from GitHub, we\nrecommended that you conduct the below steps using an active virtual\nenvironment. For information on how to create and activate a virtual\nenvironment, see the [Virtual Environment](//docs.python.org/3/tutorial/venv.html) documentation.\n\nInstall the module from PyPI\n----------------------------\n\nThe library is distributed on [PyPI](//pypi.org/project/google-ads/) and can\nbe installed using [pip](//pip.pypa.io/en/stable/installing) with the\nfollowing command: \n\n python -m pip install google-ads\n\nInstall the library from GitHub\n-------------------------------\n\nThe source code for the library can be cloned from [GitHub](https://github.com/googleads/google-ads-python/)\nonto your local machine. It's useful to clone the source code in order to easily\nexecute the examples or to develop the library itself. For reference, running\none of the authentication examples is a required step in configuring the library\nfor use.\n\n1. Ensure that `python3.8` or later is present in your environment.\n The simplest way is to use [`pyenv`](//github.com/pyenv/pyenv-installer):\n\n pyenv local 3.8\n\n2. Clone the client library from GitHub:\n\n git clone git@github.com:googleads/google-ads-python.git\n\n3. Enter the repository and install it:\n\n cd google-ads-python\n python -m pip install .\n\n4. If you intend to develop the library, run the unit tests before and after\n making any changes:\n\n 1. Ensure you have all supported versions of the Python language available in\n your environment. Using `pyenv`::\n\n pyenv local 3.8 3.9 3.10 3.11 3.12\n\n 2. Install the test-specific dependencies of the library:\n\n python -m pip install .[tests]\n\n 3. Run the unit tests to ensure the library is functioning properly:\n\n nox\n\n 4. Optional: the unit tests can also be run using Docker. First, you must\n have [Docker installed](https://docs.docker.com/get-docker/). Then, from\n the `google-ads-python` directory, run the following:\n\n docker build -t google-ads-python:test .\n docker run -it google-ads-python:test nox"]]